PDO::exec – Execute an SQL Statement and Return the Number of Affected Rows
The article explains PHP's PDO::exec method, detailing its signature, parameters, return value, and provides a complete example showing how to delete rows from a database table and retrieve the count of affected rows.
PDO::exec is a PHP method that executes a given SQL statement in a single function call and returns the number of rows affected by the operation.
Signature: int PDO::exec(string $statement)
Parameter: $statement – the SQL statement to be prepared and executed.
Return value: The number of rows modified or deleted by the SQL statement; if no rows are affected, PDO::exec returns 0.
Example:
exec("DELETE FROM fruit WHERE colour = 'red'");
/* Output the number of deleted rows */
print("Deleted $count rows.\n");
?>Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.