According to the manual of mysql_query() and to everything I know about this function that I used so many times, it can either return a resource or FALSE if the query is a SELECT. Yet it returns TRUE from time to time.
How can this be? It never ever happened before. Is this a bug in PHP 5.3.2? Does anyone know anything about this?
The code is something like:
if (!$resource = mysql_query($query, $handle)) {
throw some exception;
}
var_dump($query);
if ($resource === true && strpos($query, 'SELECT') !== false) {
throw new Exception('mysql_query() returned TRUE for SELECT');
}
It’s pretty hard to reproduce, too. It happens only from time to time. I also noticed that it’s likely this happens at the same time the server interrupts the connection suddenly, in which case it should return FALSE…
If webbiedave isn’t on the right track, there’s only one codepath that allows for this situation in the php source:
…
I would consider this a bug. Especially since there’s no real way to verify this – mysql_num_fields in the PHP code uses the resource that you’re not getting, not the connection.
Although it’s still weird that the C version of mysql_query returns zero on lost connection – if you’re able to, try the following patch and reinstall the mysql extension: