utf8_unicode_ci似乎不是UTF8

I got something strange with my mySql database... My tables are encode in "utf8_unicode_ci", but when I make a SELECT on it, data seems not to be UTF8 because json_encode give an empty string.

I have to re browse the result to re-encode the data in UTF8...

    $q = $this->db->prepare("SELECT ...");

    $q->execute();

    $data = $q->fetchAll();

    foreach ($data as $key => $value) {
        $data[$key] = utf8_encode($value);
    }

    return $data;

After that, json_encode do his job. But I don't understand why the SELECT result from my table encode in "utf8_unicode_ci" doesn't extract the data in UTF8 directly... It is very redundant to re-browse the array...

Thanks for help

Having the Mysql tables encoded in UTF-8 is not enough. That only ensures that the data is "stored" in UTF-8. When it is "passed" to external sources, even the passing pipe has to be UTF-8 encoded. You will need to set char set for the connection link identifier as well.

It works something like so:

$mysqli = new mysqli("server", "user", "password", "test");
$mysqli->set_charset("utf8");

Also check out SET NAMES utf8