I am new to PDO objects and cannot find a single piece of documentation that will help me. Say I got a simple code to delete a row:
$count = $dbh->exec("DELETE FROM fruit WHERE colour = 'red'");
That will return affected rows, but how would I use prepared statements with that? Can use use $dbh->prepare
AND $dbh->exec
or query !?
It should be the same as any other statement:
$stmt = $dbh->prepare("DELETE FROM fruit WHERE colour = ?");
$stmt->execute(array('red'));
$count = $stmt->rowCount();
The PDO Statement rowCount() should be what you are looking to do.
EDIT
Fixed by adding the ->rowCount()
which will return the row count. ->execute
in a statement will return a bool
, true
or false
whether the query errored out or not. Of course all of this information is readily available at the PDO Statement Manual
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With