diff --git a/src/wp-includes/wp-db.php b/src/wp-includes/wp-db.php
index 066e851..c2e576c 100644
|
a
|
b
|
class wpdb { |
| 780 | 780 | if ( $this->use_mysqli ) { |
| 781 | 781 | if ( function_exists( 'mysqli_set_charset' ) && $this->has_cap( 'set_charset' ) ) { |
| 782 | 782 | mysqli_set_charset( $dbh, $charset ); |
| 783 | | } else { |
| 784 | | $query = $this->prepare( 'SET NAMES %s', $charset ); |
| 785 | | if ( ! empty( $collate ) ) |
| 786 | | $query .= $this->prepare( ' COLLATE %s', $collate ); |
| 787 | | mysqli_query( $dbh, $query ); |
| 788 | 783 | } |
| | 784 | $query = $this->prepare( 'SET NAMES %s', $charset ); |
| | 785 | if ( ! empty( $collate ) ) |
| | 786 | $query .= $this->prepare( ' COLLATE %s', $collate ); |
| | 787 | mysqli_query( $dbh, $query ); |
| 789 | 788 | } else { |
| 790 | 789 | if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset' ) ) { |
| 791 | 790 | mysql_set_charset( $charset, $dbh ); |
| 792 | | } else { |
| 793 | | $query = $this->prepare( 'SET NAMES %s', $charset ); |
| 794 | | if ( ! empty( $collate ) ) |
| 795 | | $query .= $this->prepare( ' COLLATE %s', $collate ); |
| 796 | | mysql_query( $query, $dbh ); |
| 797 | 791 | } |
| | 792 | $query = $this->prepare( 'SET NAMES %s', $charset ); |
| | 793 | if ( ! empty( $collate ) ) |
| | 794 | $query .= $this->prepare( ' COLLATE %s', $collate ); |
| | 795 | mysql_query( $query, $dbh ); |
| 798 | 796 | } |
| 799 | 797 | } |
| 800 | 798 | } |
diff --git a/tests/phpunit/tests/db/charset.php b/tests/phpunit/tests/db/charset.php
index 584a628..6ef9552 100644
|
a
|
b
|
class Tests_DB_Charset extends WP_UnitTestCase { |
| 16 | 16 | |
| 17 | 17 | public static function setUpBeforeClass() { |
| 18 | 18 | require_once( dirname( dirname( __FILE__ ) ) . '/db.php' ); |
| 19 | | |
| | 19 | |
| 20 | 20 | self::$_wpdb = new wpdb_exposed_methods_for_testing(); |
| 21 | 21 | } |
| 22 | 22 | |
| … |
… |
class Tests_DB_Charset extends WP_UnitTestCase { |
| 891 | 891 | |
| 892 | 892 | $this->assertEquals( $safe_query, $stripped_query ); |
| 893 | 893 | } |
| | 894 | |
| | 895 | /** |
| | 896 | * @ticket 36649 |
| | 897 | */ |
| | 898 | function test_set_charset_changes_the_connection_collation() { |
| | 899 | self::$_wpdb->set_charset( self::$_wpdb->dbh, 'utf8', 'utf8_general_ci' ); |
| | 900 | $results = self::$_wpdb->get_results( "SHOW VARIABLES WHERE Variable_name='collation_connection'" ); |
| | 901 | $this->assertEquals( 'utf8_general_ci', $results[0]->Value ); |
| | 902 | |
| | 903 | self::$_wpdb->set_charset( self::$_wpdb->dbh, 'utf8mb4', 'utf8mb4_unicode_ci' ); |
| | 904 | $results = self::$_wpdb->get_results( "SHOW VARIABLES WHERE Variable_name='collation_connection'" ); |
| | 905 | $this->assertEquals( 'utf8mb4_unicode_ci', $results[0]->Value ); |
| | 906 | } |
| 894 | 907 | } |