Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL / PDO FOUND_ROWS() sometimes falsely returning 0

We have a laravel 4.1 application that used to run under PHP 5.4, however since upgrading to 5.6.13 (And today to 5.6.14) I've noticed that queries have started to sometimes return 0 for FOUND_ROWS(). On some of our queries it seems to be intermittent, however on others it's more of a permanent issue.

The biggest impacted sets are those with sub queries.

We're using PDO (we're not using the laravel models, just interacting directly with its PDO object). MySQL hasn't been modified in this time frame either.

Tried all sorts - one suggestion was to set trace mode to 0, that didn't help though. I tried setting PDO::MYSQL_ATTR_USE_BUFFERED_QUERY to false, however that leads to a PDO error when you try and select FOUND_ROWS() (Can't get the exact message right now).

Short of rolling back to 5.4 (please God no), I'm completely stuck...

Running these queries directly in MySQL, and then running FOUND_ROWS() always returns the correct results.

like image 540
BenOfTheNorth Avatar asked Dec 04 '15 19:12

BenOfTheNorth


1 Answers

New Relic has issues

New Relic Application has some issues. NewRelic Application Monitoring Daemon or extension is interfering with the results of FOUND_ROWS()

The current workaround is =>

newrelic.transaction_tracer.explain_enabled = false

How to use FOUND_ROWS

It's not clear yet what your sql PDO queries are. Still trying my way of using FOUND_ROWS() with PDO. Check if you are using same way or please provide some queries your are trying.

$db = new PDO(DSN...); 
$db->setAttribute(array(PDO::MYSQL_USE_BUFFERED_QUERY=>FALSE)); 
$rs  = $db->query('SELECT SQL_CALC_FOUND_ROWS * FROM table LIMIT 5,15'); 
$rs1 = $db->query('SELECT FOUND_ROWS()'); 
$rowCount = (int) $rs1->fetchColumn();  
like image 68
Somnath Muluk Avatar answered Nov 15 '22 17:11

Somnath Muluk