diff options
Diffstat (limited to 'includes/db/DatabaseMysql.php')
-rw-r--r-- | includes/db/DatabaseMysql.php | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index 823d9b67..5b151477 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -33,10 +33,12 @@ class DatabaseMysql extends DatabaseMysqlBase { * @return resource False on error */ protected function doQuery( $sql ) { + $conn = $this->getBindingHandle(); + if ( $this->bufferResults() ) { - $ret = mysql_query( $sql, $this->mConn ); + $ret = mysql_query( $sql, $conn ); } else { - $ret = mysql_unbuffered_query( $sql, $this->mConn ); + $ret = mysql_unbuffered_query( $sql, $conn ); } return $ret; @@ -48,8 +50,7 @@ class DatabaseMysql extends DatabaseMysqlBase { * @throws DBConnectionError */ protected function mysqlConnect( $realServer ) { - # Fail now - # Otherwise we get a suppressed fatal error, which is very hard to track down + # Avoid a suppressed fatal error, which is very hard to track down if ( !extension_loaded( 'mysql' ) ) { throw new DBConnectionError( $this, @@ -73,6 +74,9 @@ class DatabaseMysql extends DatabaseMysqlBase { $conn = false; + # The kernel's default SYN retransmission period is far too slow for us, + # so we use a short timeout plus a manual retry. Retrying means that a small + # but finite rate of SYN packet loss won't cause user-visible errors. for ( $i = 0; $i < $numAttempts && !$conn; $i++ ) { if ( $i > 1 ) { usleep( 1000 ); @@ -93,8 +97,10 @@ class DatabaseMysql extends DatabaseMysqlBase { * @return bool */ protected function mysqlSetCharset( $charset ) { + $conn = $this->getBindingHandle(); + if ( function_exists( 'mysql_set_charset' ) ) { - return mysql_set_charset( $charset, $this->mConn ); + return mysql_set_charset( $charset, $conn ); } else { return $this->query( 'SET NAMES ' . $charset, __METHOD__ ); } @@ -104,14 +110,18 @@ class DatabaseMysql extends DatabaseMysqlBase { * @return bool */ protected function closeConnection() { - return mysql_close( $this->mConn ); + $conn = $this->getBindingHandle(); + + return mysql_close( $conn ); } /** * @return int */ function insertId() { - return mysql_insert_id( $this->mConn ); + $conn = $this->getBindingHandle(); + + return mysql_insert_id( $conn ); } /** @@ -129,7 +139,9 @@ class DatabaseMysql extends DatabaseMysqlBase { * @return int */ function affectedRows() { - return mysql_affected_rows( $this->mConn ); + $conn = $this->getBindingHandle(); + + return mysql_affected_rows( $conn ); } /** @@ -137,9 +149,11 @@ class DatabaseMysql extends DatabaseMysqlBase { * @return bool */ function selectDB( $db ) { + $conn = $this->getBindingHandle(); + $this->mDBname = $db; - return mysql_select_db( $db, $this->mConn ); + return mysql_select_db( $db, $conn ); } protected function mysqlFreeResult( $res ) { @@ -183,10 +197,14 @@ class DatabaseMysql extends DatabaseMysqlBase { } protected function mysqlRealEscapeString( $s ) { - return mysql_real_escape_string( $s, $this->mConn ); + $conn = $this->getBindingHandle(); + + return mysql_real_escape_string( $s, $conn ); } protected function mysqlPing() { - return mysql_ping( $this->mConn ); + $conn = $this->getBindingHandle(); + + return mysql_ping( $conn ); } } |