Using utf8mb4 with php and mysql

前端 未结 4 2068
时光取名叫无心
时光取名叫无心 2020-12-02 14:42

I have read that mysql >= 5.5.3 fully supports every possible character if you USE the encoding utf8mb4 for a certain table/column http://mathiasbynens.be/n

4条回答
  •  时光说笑
    2020-12-02 15:26

    This is what i used, and worked good for my problem using euro € sign and conversion for json_encode failure.

    php configurations script( api etc..)

    header('Content-Type: text/html; charset=utf-8');
    ini_set("default_charset", "UTF-8");
    mb_internal_encoding("UTF-8");
    iconv_set_encoding("internal_encoding", "UTF-8");
    iconv_set_encoding("output_encoding", "UTF-8");
    

    mysql tables / or specific columns

    utf8mb4
    

    mysql PDO connection

    $dsn = 'mysql:host=yourip;dbname=XYZ;charset=utf8mb4';
    

    (...your connection ...)

    before execute query (might not be required):

    $dbh->exec("set names utf8mb4");
    

提交回复
热议问题