From: Tyler Anthony Romeo Date: Tue, 4 Sep 2012 03:55:18 +0000 (-0400) Subject: (bug 39287) Fixed error checking in DatabaseMysql::fetchObject. X-Git-Tag: 1.31.0-rc.0~22467^2 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=b69cc58b7fda191872ebbc315ea635983d710c48;p=lhc%2Fweb%2Fwiklou.git (bug 39287) Fixed error checking in DatabaseMysql::fetchObject. According to the libmysql API documentation, mysql_fetch_row, upon which the PHP functions mysql_fetch_object, etc. are based on, does not reset the error number or message upon success. So calling mysql_errno() after a successful fetch may return the error of the previous function call. This commit changes DatabaseMysql::fetchObject and similar functions to only check for specific error numbers that are explicitly documented to be expected from mysql_fetch_*. Change-Id: Iacb78828885a8a0d4e499a681d938a6adf651582 --- diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index faa09ada7b..7f389da904 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -203,7 +203,13 @@ class DatabaseMysql extends DatabaseBase { wfSuppressWarnings(); $row = mysql_fetch_object( $res ); wfRestoreWarnings(); - if( $this->lastErrno() ) { + + $errno = $this->lastErrno(); + // Unfortunately, mysql_fetch_object does not reset the last errno. + // Only check for CR_SERVER_LOST and CR_UNKNOWN_ERROR, as + // these are the only errors mysql_fetch_object can cause. + // See http://dev.mysql.com/doc/refman/5.0/es/mysql-fetch-row.html. + if( $errno == 2000 || $errno == 2013 ) { throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) ); } return $row; @@ -221,7 +227,13 @@ class DatabaseMysql extends DatabaseBase { wfSuppressWarnings(); $row = mysql_fetch_array( $res ); wfRestoreWarnings(); - if ( $this->lastErrno() ) { + + $errno = $this->lastErrno(); + // Unfortunately, mysql_fetch_array does not reset the last errno. + // Only check for CR_SERVER_LOST and CR_UNKNOWN_ERROR, as + // these are the only errors mysql_fetch_object can cause. + // See http://dev.mysql.com/doc/refman/5.0/es/mysql-fetch-row.html. + if( $errno == 2000 || $errno == 2013 ) { throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) ); } return $row;