0

I recently shifted from mysqli standard to PDO in PHP. My database is written with Workbench and accessible from a remote server, handled with cPanel (phpMydamin). All my tables are in utf8_general_ci. In PHP, I use the slim library as well. I tried to handle ut8 as follow, in a ManagerDAO.class.php file calling spyc.php:

protected function __construct() {
        $this->setUpPDO();
    }

private function setUpPDO() {
    $settings = spyc_load_file(self::SETTINGSFILE);
    $this->pdo = new PDO("mysql:host=" . $settings['Host'] . ";dbname=" . $settings['DBName'].";charset=UTF8", $settings['Username'], strval($settings['Password']));
    $this->pdo->exec("SET CHARACTER SET utf8");

    $this->pdo->query("SET NAMES 'utf-8'");
}

In the index.php file I wrote:

header('Content-Type: application/json; charset=UTF-8');
ini_set( 'default_charset', 'UTF-8' );

As a result, instead of "日本語" I have "\u65e5\u672c\u8a9e" and instead of "Français" I have "Fran\u00e7ais". What is the way to solve this issue? Thank you in advance.

Edit:

After several check, we eventually looked at what we see in the android phone screen, and the words (or kanji for Japanese) are properly written. The /u enconding for none ASCII character is only in the url allowing data access from the database to the mobile app. I don't have a clue why it's encoded that way here, but it doesn't really matter as long as it's encoded properly on the smartphone.

Rick James
  • 135,179
  • 13
  • 127
  • 222
  • Have you checked out that answer http://stackoverflow.com/questions/4361459/php-pdo-charset-set-names ? – Kenjin Apr 16 '15 at 09:01
  • 1) See http://stackoverflow.com/a/279279/476 how to correctly set the connection charset. 2) Neither PDO nor MySQL will return `\u....` sequences under any circumstances. You have some additional encoding going on there. JSON? – deceze Apr 16 '15 at 09:10
  • Very possible duplicate of http://stackoverflow.com/q/22745662/476 – deceze Apr 17 '15 at 08:39
  • @deceze - I just read the answer to stackoverflow.com/q/22745662/476. You nailed it, it's seems there is actually nothing wrong with this \u encoding seen at the url. Thank you. – christophe jean-joseph Apr 17 '15 at 09:23
  • Dup of [Reference: Why are my “special” Unicode characters encoded weird using json_encode?](http://stackoverflow.com/questions/22745662/reference-why-are-my-special-unicode-characters-encoded-weird-using-json-enco) -- JSON_UNESCAPED_UNICODE flag in PHP 5.4 or higher. The other links are not relevant. – Rick James Apr 18 '15 at 01:17

0 Answers0