add_article_to_collect.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. //查询term字典
  3. require_once "../path.php";
  4. require_once "../public/_pdo.php";
  5. require_once '../public/function.php';
  6. require_once '../ucenter/function.php';
  7. $output = array();
  8. $respond = array();
  9. if(isset($_POST["id"])){
  10. $data = json_decode($_POST["data"]);
  11. $title = $_POST["title"];
  12. PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
  13. $article_id=$_POST["id"];
  14. $query = "DELETE FROM article_list WHERE article_id = ? ";
  15. PDO_Execute($query,array($article_id));
  16. if(count($data)>0){
  17. /* 开始一个事务,关闭自动提交 */
  18. $PDO->beginTransaction();
  19. $query = "INSERT INTO article_list (collect_id, article_id,level,title) VALUES (?, ?, ? , ?)";
  20. $sth = $PDO->prepare($query);
  21. foreach ($data as $row) {
  22. $sth->execute(array($row,$article_id,1,$title));
  23. }
  24. $PDO->commit();
  25. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  26. /* 识别错误且回滚更改 */
  27. $PDO->rollBack();
  28. $error = PDO_ErrorInfo();
  29. $respond['status']=1;
  30. $respond['message']=$error[2];
  31. }
  32. else{
  33. $respond['status']=0;
  34. $respond['message']="成功";
  35. }
  36. }
  37. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  38. }
  39. ?>