Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/104151
Change subject: With mysqli, avoid setting the charset twice
......................................................................
With mysqli, avoid setting the charset twice
* This uses MYSQLI_SET_CHARSET_NAME to set the charset to utf8/binary
* This replaces a live WMF hack to skip the extra round trip
Change-Id: I1718e013fcdc95163d111d460f0dd6d2190a99b1
---
M includes/db/DatabaseMysqlBase.php
M includes/db/DatabaseMysqli.php
2 files changed, 35 insertions(+), 8 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/51/104151/1
diff --git a/includes/db/DatabaseMysqlBase.php
b/includes/db/DatabaseMysqlBase.php
index 3125325..08fb2c9 100644
--- a/includes/db/DatabaseMysqlBase.php
+++ b/includes/db/DatabaseMysqlBase.php
@@ -49,7 +49,7 @@
* @throws DBConnectionError
*/
function open( $server, $user, $password, $dbName ) {
- global $wgAllDBsAreLocalhost, $wgDBmysql5, $wgSQLMode;
+ global $wgAllDBsAreLocalhost, $wgSQLMode;
wfProfileIn( __METHOD__ );
# Debugging hack -- fake cluster
@@ -113,13 +113,11 @@
}
}
- // 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 );
@@ -139,6 +137,22 @@
}
/**
+ * 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
*
* @param $realServer string
diff --git a/includes/db/DatabaseMysqli.php b/includes/db/DatabaseMysqli.php
index 6c83adb..7fe2dea 100644
--- a/includes/db/DatabaseMysqli.php
+++ b/includes/db/DatabaseMysqli.php
@@ -44,6 +44,7 @@
}
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' ) ) {
@@ -63,8 +64,15 @@
}
$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, MYSQLI_SET_CHARSET_NAME,
'utf8' );
+ } else {
+ mysqli_options( $mysqli, MYSQLI_SET_CHARSET_NAME,
'binary' );
+ }
+ $numAttempts = 2;
for ( $i = 0; $i < $numAttempts; $i++ ) {
if ( $i > 1 ) {
usleep( 1000 );
@@ -79,6 +87,11 @@
return false;
}
+ protected function connectInitCharset() {
+ // already done in mysqlConnect()
+ return true;
+ }
+
/**
* @return bool
*/
--
To view, visit https://gerrit.wikimedia.org/r/104151
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1718e013fcdc95163d111d460f0dd6d2190a99b1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits