update.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. } else {
  14. $respond['status'] = 1;
  15. $respond['message'] = "no data";
  16. echo json_encode(array(), JSON_UNESCAPED_UNICODE);
  17. exit;
  18. }
  19. if (count($aData) > 0) {
  20. add_edit_event(_WBW_EDIT_, "{$aData[0]->book}-{$aData[0]->para}-{$aData[0]->word_id}");
  21. PDO_Connect("" . _FILE_DB_USER_WBW_);
  22. /* 开始一个事务,关闭自动提交 */
  23. $PDO->beginTransaction();
  24. $query = "UPDATE wbw SET data= ? , receive_time= ? , modify_time= ? where block_id= ? and wid= ? ";
  25. $sth = $PDO->prepare($query);
  26. foreach ($aData as $data) {
  27. $sth->execute(array($data->data, mTime(), $data->time, $data->block_id, $data->word_id));
  28. }
  29. $PDO->commit();
  30. $respond = array("status" => 0, "message" => "");
  31. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  32. /* 识别错误且回滚更改 */
  33. $PDO->rollBack();
  34. $error = PDO_ErrorInfo();
  35. $respond['status'] = 1;
  36. $respond['message'] = $error[2];
  37. } else {
  38. $respond['status'] = 0;
  39. $respond['message'] = "成功";
  40. }
  41. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  42. } else {
  43. $respond['status'] = 1;
  44. $respond['message'] = "no data";
  45. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  46. }