Database: Set MySQL connection collation.
Fixes #36649. git-svn-id: https://develop.svn.wordpress.org/trunk@37320 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8692cdbecd
commit
878343d4d1
@ -780,21 +780,19 @@ class wpdb {
|
|||||||
if ( $this->use_mysqli ) {
|
if ( $this->use_mysqli ) {
|
||||||
if ( function_exists( 'mysqli_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
|
if ( function_exists( 'mysqli_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
|
||||||
mysqli_set_charset( $dbh, $charset );
|
mysqli_set_charset( $dbh, $charset );
|
||||||
} else {
|
|
||||||
$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 {
|
} else {
|
||||||
if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
|
if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
|
||||||
mysql_set_charset( $charset, $dbh );
|
mysql_set_charset( $charset, $dbh );
|
||||||
} else {
|
|
||||||
$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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ class Tests_DB_Charset extends WP_UnitTestCase {
|
|||||||
|
|
||||||
public static function setUpBeforeClass() {
|
public static function setUpBeforeClass() {
|
||||||
require_once( dirname( dirname( __FILE__ ) ) . '/db.php' );
|
require_once( dirname( dirname( __FILE__ ) ) . '/db.php' );
|
||||||
|
|
||||||
self::$_wpdb = new wpdb_exposed_methods_for_testing();
|
self::$_wpdb = new wpdb_exposed_methods_for_testing();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -891,4 +891,19 @@ class Tests_DB_Charset extends WP_UnitTestCase {
|
|||||||
|
|
||||||
$this->assertEquals( $safe_query, $stripped_query );
|
$this->assertEquals( $safe_query, $stripped_query );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 36649
|
||||||
|
*/
|
||||||
|
function test_set_charset_changes_the_connection_collation() {
|
||||||
|
self::$_wpdb->set_charset( self::$_wpdb->dbh, 'utf8', 'utf8_general_ci' );
|
||||||
|
$results = self::$_wpdb->get_results( "SHOW VARIABLES WHERE Variable_name='collation_connection'" );
|
||||||
|
$this->assertEquals( 'utf8_general_ci', $results[0]->Value );
|
||||||
|
|
||||||
|
self::$_wpdb->set_charset( self::$_wpdb->dbh, 'utf8mb4', 'utf8mb4_unicode_ci' );
|
||||||
|
$results = self::$_wpdb->get_results( "SHOW VARIABLES WHERE Variable_name='collation_connection'" );
|
||||||
|
$this->assertEquals( 'utf8mb4_unicode_ci', $results[0]->Value );
|
||||||
|
|
||||||
|
self::$_wpdb->set_charset( self::$_wpdb->dbh );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user