If webbiedave isn't on the right track, there's only one codepath that allows for this situation in the php source:
#if MYSQL_VERSION_ID < 32224
#define PHP_MYSQL_VALID_RESULT(mysql)
(mysql_num_fields(mysql)>0)
#else
#define PHP_MYSQL_VALID_RESULT(mysql)
(mysql_field_count(mysql)>0)
#endif
...
if (!mysql_result) {
if (PHP_MYSQL_VALID_RESULT(mysql->conn)) { /* query should have returned rows */
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to save result set");
RETURN_FALSE;
} else {
RETURN_TRUE; // <<< this case
}
}
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:
Index: ext/mysql/php_mysql.c
===================================================================
--- ext/mysql/php_mysql.c (revision 311719)
+++ ext/mysql/php_mysql.c (working copy)
@@ -1485,6 +1485,9 @@
if (PHP_MYSQL_VALID_RESULT(mysql->conn)) { /* query should have returned rows */
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to save result set");
RETURN_FALSE;
+ } else if( mysql_errno(mysql->conn) != 0 ) {
+ php_error_docref("http://www.mysql.com/doc" TSRMLS_CC, E_WARNING, "%s", mysql_error(mysql->conn));
+ RETURN_FALSE;
} else {
RETURN_TRUE;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…