Updating Records with PHP
The last technique I’ll introduce in this chapter is how to update database records with a PHP script. Doing so requires use of the UPDATE query, and its successful execution can be verified with PHP’s mysql_affected_rows() function.
While the mysql_num_rows() function will return the number of rows generated by a SELECT query, mysql_affected_rows() returns the number of rows affected by an INSERT, UPDATE, or DELETE query. It’s used like so:
$num = mysql_affected_rows($dbc);
The one argument the function takes is the database connection ($dbc), not the results of the previous query ($result). This argument is optional, though, so I’ll often omit it in order to avoid problems (like inadvertently using $result).
The ...
Get PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.