PHP 5.2.17 (cli) (built: Jan 17 2011 12:51:24) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
Here is my function
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());
}
}
I'm calling it and passing an id of the row in the database. The row gets removed from the database, but the if ($affected_rows == 1) { is always false. errorInfo() returns an array of [0] => 0000.
I've been through the PDO manual and I was referencing http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers#INSERT.2C_DELETE.2C_UPDATE_Prepared_Queries
Shouldn't rowcount() return 1 (or however many id's had the value passed to remove?
Thanks in advance.
PDO::exec
expects an SQL statement string. If you prepare a statement, you must call PDOStatement::execute
instead
$delete_loan->execute($params);