0){ /* 开始一个事务,关闭自动提交 */ $PDO->beginTransaction(); $query = "INSERT INTO article_list (collect_id, article_id,level,title) VALUES (?, ?, ? , ?)"; $sth = $PDO->prepare($query); foreach ($data as $row) { $sth->execute(array($row,$article_id,1,$title)); } $PDO->commit(); if (!$sth || ($sth && $sth->errorCode() != 0)) { /* 识别错误且回滚更改 */ $PDO->rollBack(); $error = PDO_ErrorInfo(); $respond['status']=1; $respond['message']=$error[2]; } else{ $respond['status']=0; $respond['message']="成功"; } } echo json_encode($respond, JSON_UNESCAPED_UNICODE); } ?>