WordPress 4.6.1
[autoinstalls/wordpress.git] / wp-includes / wp-db.php
index 2f8dbcf96968353f799f6fab46a737f408c762e4..8ebee4c40e2042a5b279e24a0fd03d40fad06a3a 100644 (file)
@@ -734,6 +734,9 @@ class wpdb {
         * @since 3.1.0
         */
        public function init_charset() {
+               $charset = '';
+               $collate = '';
+
                if ( function_exists('is_multisite') && is_multisite() ) {
                        $charset = 'utf8';
                        if ( defined( 'DB_COLLATE' ) && DB_COLLATE ) {
@@ -808,22 +811,29 @@ class wpdb {
                if ( ! isset( $collate ) )
                        $collate = $this->collate;
                if ( $this->has_cap( 'collation' ) && ! empty( $charset ) ) {
+                       $set_charset_succeeded = true;
+
                        if ( $this->use_mysqli ) {
                                if ( function_exists( 'mysqli_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
-                                       mysqli_set_charset( $dbh, $charset );
+                                       $set_charset_succeeded = mysqli_set_charset( $dbh, $charset );
+                               }
+
+                               if ( $set_charset_succeeded ) {
+                                       $query = $this->prepare( 'SET NAMES %s', $charset );
+                                       if ( ! empty( $collate ) )
+                                               $query .= $this->prepare( ' COLLATE %s', $collate );
+                                       mysqli_query( $dbh, $query );
                                }
-                               $query = $this->prepare( 'SET NAMES %s', $charset );
-                               if ( ! empty( $collate ) )
-                                       $query .= $this->prepare( ' COLLATE %s', $collate );
-                               mysqli_query( $dbh, $query );
                        } else {
                                if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
-                                       mysql_set_charset( $charset, $dbh );
+                                       $set_charset_succeeded = mysql_set_charset( $charset, $dbh );
+                               }
+                               if ( $set_charset_succeeded ) {
+                                       $query = $this->prepare( 'SET NAMES %s', $charset );
+                                       if ( ! empty( $collate ) )
+                                               $query .= $this->prepare( ' COLLATE %s', $collate );
+                                       mysql_query( $query, $dbh );
                                }
-                               $query = $this->prepare( 'SET NAMES %s', $charset );
-                               if ( ! empty( $collate ) )
-                                       $query .= $this->prepare( ' COLLATE %s', $collate );
-                               mysql_query( $query, $dbh );
                        }
                }
        }