Skip to content

Instantly share code, notes, and snippets.

@miya0001
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miya0001/91c837a1d3a0b75cd233 to your computer and use it in GitHub Desktop.
Save miya0001/91c837a1d3a0b75cd233 to your computer and use it in GitHub Desktop.
MySQL UTF-8 4 Bytes character problem
<?php
class SampleTest extends WP_UnitTestCase {
/**
* @test
*/
function utf8_test()
{
global $wp_version;
global $wpdb;
$this->assertSame( '4.2', $wp_version );
// post_title is sushi
$post_id = $this->factory->post->create( array( 'post_title' => '🍣' ) );
// search by beer
$result = $wpdb->get_var( $wpdb->prepare(
"SELECT ID FROM $wpdb->posts where post_title=%s", '🍺'
) );
// It should be null but 3
$this->assertSame( NULL, $result ); // fail
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment