2
0

new.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. get xml doc from db
  4. */
  5. require_once "../config.php";
  6. require_once "../public/_pdo.php";
  7. require_once "../public/function.php";
  8. $aData = json_decode($_POST["data"]);
  9. PDO_Connect(_FILE_DB_SENTENCE_,_DB_USERNAME_,_DB_PASSWORD_);
  10. /* 开始一个事务,关闭自动提交 */
  11. $PDO->beginTransaction();
  12. $query = "INSERT INTO "._TABLE_SENTENCE_." ( uid , block_uid , book_id , paragraph , word_start , word_end , author , editor_uid , content , language , modify_time , updated_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,now())";
  13. $sth = $PDO->prepare($query);
  14. foreach ($aData as $data) {
  15. $sth->execute(
  16. array($data->id,
  17. $data->blockid,
  18. $data->book,
  19. $data->paragraph,
  20. $data->begin,
  21. $data->end,
  22. $data->author,
  23. $data->editor,
  24. $data->text,
  25. $data->lang,
  26. mTime()
  27. ));
  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);