update.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. get xml doc from db
  4. */
  5. require_once "../path.php";
  6. require_once "../public/_pdo.php";
  7. require_once "../public/function.php";
  8. require_once "../ucenter/active.php";
  9. $respond['status']=0;
  10. $respond['message']="";
  11. if(isset($_POST["data"])){
  12. $aData=json_decode($_POST["data"]);
  13. }
  14. else{
  15. $respond['status']=1;
  16. $respond['message']="no data";
  17. echo json_encode(array(), JSON_UNESCAPED_UNICODE);
  18. exit;
  19. }
  20. if(count($aData)>0){
  21. add_edit_event(_WBW_EDIT_,"{$aData[0]->book}-{$aData[0]->para}-{$aData[0]->word_id}");
  22. PDO_Connect("sqlite:"._FILE_DB_USER_WBW_);
  23. /* 开始一个事务,关闭自动提交 */
  24. $PDO->beginTransaction();
  25. $query="UPDATE wbw SET data= ? , receive_time= ? , modify_time= ? where block_id= ? and wid= ? ";
  26. $sth = $PDO->prepare($query);
  27. foreach ($aData as $data) {
  28. $sth->execute(array($data->data,mTime(),$data->time,$data->block_id,$data->word_id));
  29. }
  30. $PDO->commit();
  31. $respond=array("status"=>0,"message"=>"");
  32. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  33. /* 识别错误且回滚更改 */
  34. $PDO->rollBack();
  35. $error = PDO_ErrorInfo();
  36. $respond['status']=1;
  37. $respond['message']=$error[2];
  38. }
  39. else{
  40. $respond['status']=0;
  41. $respond['message']="成功";
  42. }
  43. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  44. }
  45. else{
  46. $respond['status']=1;
  47. $respond['message']="no data";
  48. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  49. }
  50. ?>