* @throws DBConnectionError
*/
function open( $server, $user, $password, $dbName ) {
- global $wgAllDBsAreLocalhost;
+ global $wgAllDBsAreLocalhost, $wgDBmysql5, $wgSQLMode;
wfProfileIn( __METHOD__ );
# Load mysql.so if we don't have it
$this->mPassword = $password;
$this->mDBname = $dbName;
- wfProfileIn("dbconnect-$server");
+ $connFlags = 0;
+ if ( $this->mFlags & DBO_SSL ) {
+ $connFlags |= MYSQL_CLIENT_SSL;
+ }
+ if ( $this->mFlags & DBO_COMPRESS ) {
+ $connFlags |= MYSQL_CLIENT_COMPRESS;
+ }
+
+ wfProfileIn( "dbconnect-$server" );
# 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
usleep( 1000 );
}
if ( $this->mFlags & DBO_PERSISTENT ) {
- $this->mConn = mysql_pconnect( $realServer, $user, $password );
+ $this->mConn = mysql_pconnect( $realServer, $user, $password, $connFlags );
} else {
# Create a new connection...
- $this->mConn = mysql_connect( $realServer, $user, $password, true );
+ $this->mConn = mysql_connect( $realServer, $user, $password, true, $connFlags );
}
#if ( $this->mConn === false ) {
#$iplus = $i + 1;
#wfLogDBError("Connect loop error $iplus of $max ($server): " . mysql_errno() . " - " . mysql_error()."\n");
#}
}
- $phpError = $this->restoreErrorHandler();
+ $error = $this->restoreErrorHandler();
+
+ wfProfileOut( "dbconnect-$server" );
+
# Always log connection errors
if ( !$this->mConn ) {
- $error = $phpError;
if ( !$error ) {
$error = $this->lastError();
}
wfLogDBError( "Error connecting to {$this->mServer}: $error\n" );
- wfDebug( "DB connection error\n" );
- wfDebug( "Server: $server, User: $user, Password: " .
+ wfDebug( "DB connection error\n" .
+ "Server: $server, User: $user, Password: " .
substr( $password, 0, 3 ) . "..., error: " . $error . "\n" );
- }
- wfProfileOut("dbconnect-$server");
+ wfProfileOut( __METHOD__ );
+ $this->reportConnectionError( $error );
+ }
- if ( $dbName != '' && $this->mConn !== false ) {
+ if ( $dbName != '' ) {
wfSuppressWarnings();
$success = mysql_select_db( $dbName, $this->mConn );
wfRestoreWarnings();
if ( !$success ) {
- $error = "Error selecting database $dbName on server {$this->mServer} " .
- "from client host " . wfHostname() . "\n";
- wfLogDBError(" Error selecting database $dbName on server {$this->mServer} \n");
- wfDebug( $error );
- }
- } else {
- # Delay USE query
- $success = (bool)$this->mConn;
- }
+ wfLogDBError( "Error selecting database $dbName on server {$this->mServer}\n" );
+ wfDebug( "Error selecting database $dbName on server {$this->mServer} " .
+ "from client host " . wfHostname() . "\n" );
- if ( $success ) {
- // Tell the server we're communicating with it in UTF-8.
- // This may engage various charset conversions.
- global $wgDBmysql5;
- if( $wgDBmysql5 ) {
- $this->query( 'SET NAMES utf8', __METHOD__ );
- } else {
- $this->query( 'SET NAMES binary', __METHOD__ );
- }
- // Set SQL mode, default is turning them all off, can be overridden or skipped with null
- global $wgSQLMode;
- if ( is_string( $wgSQLMode ) ) {
- $mode = $this->addQuotes( $wgSQLMode );
- $this->query( "SET sql_mode = $mode", __METHOD__ );
+ wfProfileOut( __METHOD__ );
+ $this->reportConnectionError( "Error selecting database $dbName" );
}
+ }
- // Turn off strict mode if it is on
+ // Tell the server we're communicating with it in UTF-8.
+ // This may engage various charset conversions.
+ if( $wgDBmysql5 ) {
+ $this->query( 'SET NAMES utf8', __METHOD__ );
} else {
- $this->reportConnectionError( $phpError );
+ $this->query( 'SET NAMES binary', __METHOD__ );
+ }
+ // Set SQL mode, default is turning them all off, can be overridden or skipped with null
+ if ( is_string( $wgSQLMode ) ) {
+ $mode = $this->addQuotes( $wgSQLMode );
+ $this->query( "SET sql_mode = $mode", __METHOD__ );
}
- $this->mOpened = $success;
+ $this->mOpened = true;
wfProfileOut( __METHOD__ );
- return $success;
+ return true;
}
/**
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;
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;
* @param $delVar string
* @param $joinVar string
* @param $conds array|string
- * @param $fname bool
+ * @param bool|string $fname bool
+ * @throws DBUnexpectedError
* @return bool|ResultWrapper
*/
function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabaseBase::deleteJoin' ) {
}
-/**
- * Legacy support: Database == DatabaseMysql
- *
- * @deprecated in 1.16
- */
-class Database extends DatabaseMysql {}
-
/**
* Utility class.
* @ingroup Database