PDO::exec() — Execute an SQL statement and return the number of affected rows
- PDO::exec() executes an SQL statement in a single function call, returning the number of rows affected by the statement.
- PDO::exec() does not return results from a SELECT statement.
- For a SELECT statement that you only need to issue once during your program, consider issuing PDO::query().
- For a statement that you need to issue multiple times, prepare a PDOStatement object with PDO::prepare() and issue the statement with PDOStatement::execute().
- PDO::exec() returns the number of rows that were modified or deleted by the SQL statement you issued. If no rows were affected, PDO::exec() returns 0.
Example #1 Issuing a DELETE statement
<?php $db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'username', 'password'); /* Delete all rows from the FRUIT table */ $count = $db->exec("DELETE FROM fruit WHERE colour = 'red'"); /* Return number of rows that were deleted */ print("Deleted $count rows.\n"); ?>
Related Results :
- Related Posts are generally User Blog posts.
- or Other tutorials from other networks of w3clan.com.
- Any registered user can create related posts based on search term tags.