Whats is the difference between mysql_num_rows() and mysql_affected_rows()? mysql_num_rows() is used together with select statements while the mysql_affected_rows() is used with update, delete and insert statements.
An example of mysql_affected_rows().
$result = mysql_query( "INSERT INTO mysqltable VALUES( NULL, '$value' )" ); $rows = mysql_affected_rows(); // returns 1
An example of mysql_num_rows().
$result = mysql_query( "SELECT field FROM mysqltable" ); $rows = mysql_num_rows( $result );
3 Comments
11:27 am on February 11th, 2010:
Thanks for the very helpful info!
6:06 pm on September 22nd, 2011:
On a SELECT query, mysql_affected_rows() returns the number of rows found, while mysql_num_rows() returns the number of rows returned. Usually this is the same thing, but it could be different if you have LIMIT or GROUP BY or something similar that would alter the number of rows that get returned.
12:31 am on December 7th, 2011:
Thanks for the clarification. Thanks to a great long-tail keyword search I found this easy clarification which makes my late night of programming a little lighter. Thank you.
Leave a Reply
Topics
Recent Comments
Latest Tweets