X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fdb%2FDatabaseMysql.php;h=5b15147777c68ae7034fc88783f9358874f15deb;hb=cc4abcc7a5768f931750b7082ac5e64d3124eaa6;hp=1314b122fb229361b1e8fcff5a9460a420102477;hpb=6373f9b2558db957d031be35b5fa7f6f19616054;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index 1314b122fb..5b15147777 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -28,25 +28,34 @@ * @see Database */ class DatabaseMysql extends DatabaseMysqlBase { - /** - * @param $sql string - * @return resource + * @param string $sql + * @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; } + /** + * @param string $realServer + * @return bool|resource MySQL Database connection or false on failure to connect + * @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, "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n" ); + throw new DBConnectionError( + $this, + "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n" + ); } $connFlags = 0; @@ -65,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 ); @@ -81,11 +93,14 @@ class DatabaseMysql extends DatabaseMysqlBase { } /** + * @param string $charset * @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__ ); } @@ -95,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 ); } /** @@ -120,23 +139,21 @@ class DatabaseMysql extends DatabaseMysqlBase { * @return int */ function affectedRows() { - return mysql_affected_rows( $this->mConn ); + $conn = $this->getBindingHandle(); + + return mysql_affected_rows( $conn ); } /** - * @param $db + * @param string $db * @return bool */ function selectDB( $db ) { + $conn = $this->getBindingHandle(); + $this->mDBname = $db; - return mysql_select_db( $db, $this->mConn ); - } - /** - * @return string - */ - function getServerVersion() { - return mysql_get_server_info( $this->mConn ); + return mysql_select_db( $db, $conn ); } protected function mysqlFreeResult( $res ) { @@ -167,6 +184,10 @@ class DatabaseMysql extends DatabaseMysqlBase { return mysql_field_name( $res, $n ); } + protected function mysqlFieldType( $res, $n ) { + return mysql_field_type( $res, $n ); + } + protected function mysqlDataSeek( $res, $row ) { return mysql_data_seek( $res, $row ); } @@ -176,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 ); } }