0

I'm having a problem storing certain UTF-8 characters in MySQL.

mb_internal_encoding("UTF-8");
$pdo = new \PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_USER_PASSWORD, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

$statement = $pdo->prepare("INSERT INTO test (value) VALUES (:value)");
$statement->execute(array(":value" => "");

This ends up with the being stored as "????". The column is set to utf8mb4_unicode_ci. Some other characters that don't work are and , whereas things like ☽,☯,❁,☼,(airplane that won't show up on stackoverflow), ▲, and ▽ do work. Any idea what's going on?

zjz
  • 1
  • 1
  • Oh what the hell thought I had utf8mb4 earlier as the charset in PDO and that it still didn't work. Turns out it does work. Thanks! 2 am brainfarts... – zjz Oct 20 '15 at 08:50
  • Thanks to http://stackoverflow.com/questions/279170/utf-8-all-the-way-through. PDO should be set to 'utf8mb4' not 'utf8'. – zjz Oct 20 '15 at 08:51
  • 1
    ...and if possible via charset=.... within the dsn, not via PDO::MYSQL_ATTR_INIT_COMMAND, see http://docs.php.net/manual/en/ref.pdo-mysql.connection.php – VolkerK Oct 20 '15 at 08:53
  • See http://stackoverflow.com/a/9509773/476 – deceze Oct 20 '15 at 08:58

0 Answers0