Page 1 of 1

MySQLi Affected vs Matched

Posted: Fri Aug 12, 2011 1:03 pm
by TheAlmightyGuru
I'm having an issue with mysqli->affected_rows.

Here's my example table:

Name, Age
John Doe, 26
Bob Doe, 35

And here's my example update statement:

UPDATE table SET Age = 26 WHERE Age > 0;


Running the UPDATE and displaying mysqli->info gives me: "Rows matched: 2 Changed: 1 Warnings: 0".

I can call mysqli->affected_rows to return the Changed value. However, I want to know the Matched value. Is there a way to get the Matched value (aside from parsing the mysqli->info string)?

Re: MySQLi Affected vs Matched

Posted: Fri Aug 12, 2011 4:50 pm
by Christopher
have your tried num_rows() ?

Re: MySQLi Affected vs Matched

Posted: Fri Aug 12, 2011 11:43 pm
by Weirdan
affected_rows would return matched rows number if you connected using mysqli_real_connect() passing MYSQLI_CLIENT_FOUND_ROWS in flags parameter. As far as I know you can't get both at the same time unless you parse the info string.

Re: MySQLi Affected vs Matched

Posted: Tue Aug 16, 2011 1:57 pm
by TheAlmightyGuru
Thank you Weirdan, that solved my problem.
With that flag set, affected_rows now returns the matched records instead of the changed records.

Re: MySQLi Affected vs Matched

Posted: Tue Aug 16, 2011 2:10 pm
by phphelpme
Nice Weirdan, I will remember that one myself... lol

Best wishes