IAlex has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/95717


Change subject: Use the native set_chasert() method if available instead of SET 
NAMES
......................................................................

Use the native set_chasert() method if available instead of SET NAMES

According to the PHP manual, it is the recommended way to set the charset.

- mysql extension has it for MySQL >= 5.0.7
- mysqli extension has it for MySQL >= 5.0.6
or if using mysqlnd.

Change-Id: I8cd2f97fcad4b045c6f99ff894254847b13c6878
---
M includes/db/DatabaseMysql.php
M includes/db/DatabaseMysqlBase.php
M includes/db/DatabaseMysqli.php
3 files changed, 32 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/17/95717/1

diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php
index 956bb69..1314b12 100644
--- a/includes/db/DatabaseMysql.php
+++ b/includes/db/DatabaseMysql.php
@@ -83,6 +83,17 @@
        /**
         * @return bool
         */
+       protected function mysqlSetCharset( $charset ) {
+               if ( function_exists( 'mysql_set_charset' ) ) {
+                       return mysql_set_charset( $charset, $this->mConn );
+               } else {
+                       return $this->query( 'SET NAMES ' . $charset, 
__METHOD__ );
+               }
+       }
+
+       /**
+        * @return bool
+        */
        protected function closeConnection() {
                return mysql_close( $this->mConn );
        }
diff --git a/includes/db/DatabaseMysqlBase.php 
b/includes/db/DatabaseMysqlBase.php
index cdfa769..f43fc98 100644
--- a/includes/db/DatabaseMysqlBase.php
+++ b/includes/db/DatabaseMysqlBase.php
@@ -114,9 +114,9 @@
                // 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__ );
+                       $this->mysqlSetCharset( 'utf8' );
                } else {
-                       $this->query( 'SET NAMES binary', __METHOD__ );
+                       $this->mysqlSetCharset( 'binary' );
                }
                // Set SQL mode, default is turning them all off, can be 
overridden or skipped with null
                if ( is_string( $wgSQLMode ) ) {
@@ -139,6 +139,14 @@
        abstract protected function mysqlConnect( $realServer );
 
        /**
+        * Set the character set of the MySQL link
+        *
+        * @param $charset string
+        * @return bool
+        */
+       abstract protected function mysqlSetCharset( $charset );
+
+       /**
         * @param $res ResultWrapper
         * @throws DBUnexpectedError
         */
diff --git a/includes/db/DatabaseMysqli.php b/includes/db/DatabaseMysqli.php
index 7761abe..5b2e11d 100644
--- a/includes/db/DatabaseMysqli.php
+++ b/includes/db/DatabaseMysqli.php
@@ -82,6 +82,17 @@
        /**
         * @return bool
         */
+       protected function mysqlSetCharset( $charset ) {
+               if ( method_exists( $this->mConn, 'set_charset' ) ) {
+                       return $this->mConn->set_charset( $charset );
+               } else {
+                       return $this->query( 'SET NAMES ' . $charset, 
__METHOD__ );
+               }
+       }
+
+       /**
+        * @return bool
+        */
        protected function closeConnection() {
                return $this->mConn->close();
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/95717
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8cd2f97fcad4b045c6f99ff894254847b13c6878
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: IAlex <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to