Fishtrap

php and other stuff I know

Unable to save result set … : tracking down the query in Drupal

| 0 comments

I started getting a warning appearing in my logs generated by mysql_query

mysql_query() [function.mysql-query]: Unable to save result set in /includes/database.mysql.inc on line 116.

Ok so this was obviously a problem with one query that was either hitting a corrupt table or was in error in some other way.

The only problem is that of course that in Drupal in common with most modern PHP applications mysql_query is wrapped in some way so that all queries will pass through this line. Added to that nothing seemed to be reported either by mysql_error() or mysql_errno I was getting frustrated about finding out which of the 30 or so queries on the page were in generating the error. Finally I read the mysql_query docs carefully and discovered that if the $result of the function is false there had been an error it simply remained to output the query that returned false.

    $result = mysql_query($query, $active_db);
if (false === $result) {
var_dump($query);
}

From then it was just a simple matter of running the query in the mysql client. The error turned out to be a subquery returning more than one row.

Leave a Reply

Required fields are marked *.

*