PHP PDO Delete rowCount始终返回0
PHP 5.2.17 cli生成日期:2011年1月17日12:51:24 版权c 1997-2010 PHP集团 Zend Engine v2.2.0,版权所有c 1998-2010 Zend Technologies 这是我的功能PHP PDO Delete rowCount始终返回0,php,mysql,pdo,delete-row,rowcount,Php,Mysql,Pdo,Delete Row,Rowcount,PHP 5.2.17 cli生成日期:2011年1月17日12:51:24 版权c 1997-2010 PHP集团 Zend Engine v2.2.0,版权所有c 1998-2010 Zend Technologies 这是我的功能 public function remove($id){ $params = array(':id' => $id); $delete_loan = $this->ext_conn->prepare("DELETE
public function remove($id){
$params = array(':id' => $id);
$delete_loan = $this->ext_conn->prepare("DELETE FROM loan_program WHERE id = :id");
$delete_loan->exec($params);
$affected_rows = $delete_loan->rowCount(); //and not this?
if ($affected_rows == 1) {
return array('status' => 'success');
} else {
return array('status' => 'failure', 'reason' => 'delete_failed', 'rowcount' => $affected_rows, 'errornfo' => $delete_loan->errorInfo());
}
}
我调用它并在数据库中传递行的id。该行将从数据库中删除,但if$infected_rows==1{始终为false。errorInfo返回一个[0]=>0000的数组
我已经阅读了PDO手册,并参考了
rowcount不应该返回1,或者不管传递了多少个id来删除该值
提前感谢。需要SQL语句字符串。如果准备语句,则必须调用
应该是这样,但这假定id是该表上的唯一/主键。是否检查了是否有重复记录?如果确定,exec方法将返回受影响的行directly@ChristianKoch如果它是一个有效的调用的话,它会的。但是$delete\u loan->exec…给出了一个未定义的方法错误。
$delete_loan->execute($params);