dict_updata_user.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. 更新用户字典,已经不使用了
  4. */
  5. include "./_pdo.php";
  6. include "config.php";
  7. $serverError="";
  8. $serverReturn="";
  9. $serverOp="";
  10. $input = file_get_contents("php://input");
  11. $xml = simplexml_load_string($input);
  12. $db_file = $dir_dict_user . $file_dict_user_default;
  13. PDO_Connect("sqlite:$db_file");
  14. $wordsList = $xml->xpath('//word');
  15. $recorderCount=0;
  16. /**/
  17. foreach($wordsList as $ws){
  18. $id=$ws->id;
  19. if($id=="0"){
  20. //new recorder
  21. $query="INSERT INTO dict ('id','pali','type','gramma','parent','mean','detail','factors','factormean','confer','class','lock','tag') VALUES (null,?,?,?,?,?,?,?,?,?,?,?,?)";
  22. $params=array($ws->pali,$ws->type,$ws->gramma,$ws->parent,$ws->mean,$ws->note,$ws->factors,$ws->fm,$ws->confer,$ws->status,$ws->lock,$ws->tag);
  23. $stmt = @PDO_Execute($query,$params);
  24. $last_id = $PDO->lastInsertId();
  25. $serverOp="insert";
  26. $serverReturn=$last_id;
  27. }
  28. else{
  29. $query="UPDATE dict SET type = ? ,gramma = ? ,parent = ? ,mean = ? ,detail = ? ,factors = ? ,factormean = ? ,confer = ? ,class = ? ,lock = ? ,tag = ? WHERE id = ?";
  30. $params=array($ws->type,$ws->gramma,$ws->parent,$ws->mean,$ws->note,$ws->factors,$ws->fm,$ws->confer,$ws->status,$ws->lock,$ws->tag,$id);
  31. $stmt = @PDO_Execute($query,$params);
  32. $serverOp="update";
  33. $serverReturn=$id;
  34. }
  35. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  36. $error = PDO_ErrorInfo();
  37. $serverError.="error - $error[2]";
  38. $serverReturn=-1;
  39. }
  40. else{
  41. $recorderCount++;
  42. }
  43. $output='{ "sever_op":"insert" , "server_return":2345 , , "server_error":"haha"}';
  44. $output = '{"msg":[' . '{"server_op":"'.$serverOp.'","server_return":'.$serverReturn.',"server_error":"'.$serverError.'" }]}';
  45. echo $output;
  46. }
  47. ?>