MySQLi Affected vs Matched

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!

Moderator: General Moderators

Post Reply
TheAlmightyGuru
Forum Newbie
Posts: 2
Joined: Fri Aug 12, 2011 12:59 pm

MySQLi Affected vs Matched

Post 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)?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: MySQLi Affected vs Matched

Post by Christopher »

have your tried num_rows() ?
(#10850)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: MySQLi Affected vs Matched

Post 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.
TheAlmightyGuru
Forum Newbie
Posts: 2
Joined: Fri Aug 12, 2011 12:59 pm

Re: MySQLi Affected vs Matched

Post 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.
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: MySQLi Affected vs Matched

Post by phphelpme »

Nice Weirdan, I will remember that one myself... lol

Best wishes
Post Reply