June 2005
Intermediate
720 pages
20h 6m
English
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 ...
Read now
Unlock full access