my_collect_post.php 1.7 KB

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