* @throws DBConnectionError
*/
function open( $server, $user, $password, $dbName ) {
- global $wgAllDBsAreLocalhost, $wgDBmysql5, $wgSQLMode;
+ global $wgAllDBsAreLocalhost, $wgSQLMode;
wfProfileIn( __METHOD__ );
# Debugging hack -- fake cluster
}
}
- // Tell the server we're communicating with it in UTF-8.
- // This may engage various charset conversions.
- if ( $wgDBmysql5 ) {
- $this->mysqlSetCharset( 'utf8' );
- } else {
- $this->mysqlSetCharset( 'binary' );
+ // Tell the server what we're communicating with
+ if ( !$this->connectInitCharset() ) {
+ return $this->reportConnectionError( "Error setting character set" );
}
+
// Set SQL mode, default is turning them all off, can be overridden or skipped with null
if ( is_string( $wgSQLMode ) ) {
$mode = $this->addQuotes( $wgSQLMode );
return true;
}
+ /**
+ * Set the character set information right after connection
+ * @return bool
+ */
+ protected function connectInitCharset() {
+ global $wgDBmysql5;
+
+ if ( $wgDBmysql5 ) {
+ // Tell the server we're communicating with it in UTF-8.
+ // This may engage various charset conversions.
+ return $this->mysqlSetCharset( 'utf8' );
+ } else {
+ return $this->mysqlSetCharset( 'binary' );
+ }
+ }
+
/**
* Open a connection to a MySQL server
*
}
protected function mysqlConnect( $realServer ) {
+ global $wgDBmysql5;
# Fail now
# Otherwise we get a suppressed fatal error, which is very hard to track down
if ( !function_exists( 'mysqli_init' ) ) {
}
$mysqli = mysqli_init();
- $numAttempts = 2;
+ if ( $wgDBmysql5 ) {
+ // Tell the server we're communicating with it in UTF-8.
+ // This may engage various charset conversions.
+ $mysqli->options( MYSQLI_SET_CHARSET_NAME, 'utf8' );
+ } else {
+ $mysqli->options( MYSQLI_SET_CHARSET_NAME, 'binary' );
+ }
+ $numAttempts = 2;
for ( $i = 0; $i < $numAttempts; $i++ ) {
if ( $i > 1 ) {
usleep( 1000 );
return false;
}
+ protected function connectInitCharset() {
+ // already done in mysqlConnect()
+ return true;
+ }
+
/**
* @return bool
*/