my_collect_post.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. require_once "../path.php";
  3. require_once "../public/_pdo.php";
  4. require_once '../public/function.php';
  5. require_once '../hostsetting/function.php';
  6. $respond=array("status"=>0,"message"=>"");
  7. PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
  8. $query="UPDATE collect SET title = ? , subtitle = ? , summary = ?, article_list = ? , status = ? , lang = ? , receive_time= ? , modify_time= ? where id = ? ";
  9. $sth = $PDO->prepare($query);
  10. $sth->execute(array($_POST["title"] , $_POST["subtitle"] ,$_POST["summary"], $_POST["article_list"] , $_POST["status"] , $_POST["lang"] , mTime() , mTime() , $_POST["id"]));
  11. $respond=array("status"=>0,"message"=>"");
  12. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  13. $error = PDO_ErrorInfo();
  14. $respond['status']=1;
  15. $respond['message']=$error[2];
  16. }
  17. else{
  18. # 更新 article_list 表
  19. $query = "DELETE FROM article_list WHERE collect_id = ? ";
  20. PDO_Execute($query,array($_POST["id"]));
  21. $arrList = json_decode($_POST["article_list"]);
  22. if(count($arrList)>0){
  23. /* 开始一个事务,关闭自动提交 */
  24. $PDO->beginTransaction();
  25. $query = "INSERT INTO article_list (collect_id, article_id,level,title) VALUES ( ?, ?, ? , ? )";
  26. $sth = $PDO->prepare($query);
  27. foreach ($arrList as $row) {
  28. $sth->execute(array($_POST["id"],$row->article,$row->level,$row->title));
  29. }
  30. $PDO->commit();
  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. }
  38. }
  39. }
  40. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  41. ?>