Can't get found_rows
opened this issue · comments
I've got a select query with SQL_CALC_FOUND_ROWS in it, and then I'm following it with another query doing "select found_rows", but I'm not always getting the correct result.
In my test table, there are only 2 rows. But sometimes found_rows is returning 2, and sometimes it's returning 1.
I can assume this is because a different connection is being used. But I'm just following the Blog style example for creating my helper.
Ah, I see it now. It returns a reference to the connection it used when you do the query. So that way you can use that connection again to do another query like found_rows, and then it works.
Apologies, I looked at this for 2 hours before posting the issue, then spotted it 20 minutes after I did. Typical!
More specifically, when you need to share a connection with several (blocking) queries, first retrieve the db object (my $db = $mysql->db;
) and then use that same object for each of the following queries. Just don't hold onto that db object past that "transaction".