PHP / mysql gets the number of rows affected by the UPDATE statement

advertisements

With php/mysql how can i get the number of rows that a query affected?

what i tried so far:

$result = mysql_query($q);
mysql_num_rows($result);

but it says that Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource


if you're using PDO (wich i would recommend), for a direct query exec() returns the number of affected rows. for Prepared Statements theres a method called rowCount().

if you're using the mysql-functions, there's mysql_affected_rows().

EDIT:
seems like you're using the mysql-functions. mysql_num_rows, wich is what you're using, returns the length of your result set (for SELECT-Statements for example). what you need to use is mysql_affected_rows (as already said).