PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
For other type of SQL statements, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.
The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.
Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.
mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.
Thanks. At about the 20th time of reading, i understood it.
A separate point: strange that mysql_affected_rows() takes no resource $result parameter, mysql_num_rows() does. Why is this? It say mysql_affected_rows() acts on the last query. Is this referring to the last query to mysql within the specific script, or the last query to mysql from any script?
It's not strange. mysql_query does not return a result resource for the sql statements [INSERT,UPDATE,REPLACE,DELETE] mysql_affected_rows is meant for -> you can't pass a result resource you mysql_affected_rows.
OK. So it's possible, if you have more than one user using you site, that when mysql_affected_rows() is called, it may return a value not for the current script, but for another user's running of the script? For example, if the SQL UPDATE etc happens for user "a", then before that user gets a chance to call mysql_affected_rows(), user "b" comes along and also does a SQL statement. User "a" will then be using the mysql_affected_rows() from user "b". It sucks if there is even the remotest possibility of this happening...