my_collect_post.php 1.8 KB

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