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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 calledrowCount().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 ismysql_affected_rows(as already said).