2
0

new.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_);
  10. /* 开始一个事务,关闭自动提交 */
  11. $PDO->beginTransaction();
  12. $query = "INSERT INTO sentence ('id','block_id','book','paragraph','begin','end','tag','author','editor','text','language','ver','status','modify_time','receive_time') VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  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->tag,
  23. $data->author,
  24. $data->editor,
  25. $data->text,
  26. $data->lang,
  27. 1,
  28. 1,
  29. mTime(),
  30. mTime(),
  31. ));
  32. }
  33. $PDO->commit();
  34. $respond = array("status" => 0, "message" => "");
  35. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  36. /* 识别错误且回滚更改 */
  37. $PDO->rollBack();
  38. $error = PDO_ErrorInfo();
  39. $respond['status'] = 1;
  40. $respond['message'] = $error[2];
  41. } else {
  42. $respond['status'] = 0;
  43. $respond['message'] = "成功";
  44. }
  45. echo json_encode($respond, JSON_UNESCAPED_UNICODE);