when initializing PDO - should I do: charset=UTF8 or charset=UTF8MB4?

后端 未结 1 1912
终归单人心
终归单人心 2020-12-31 02:39

when initializing PDO - should I do: charset=UTF8 or charset=UTF8MB4 ?

here\'s my intialization:

            $dsn = \'mysql:host=example.com;dbname=t         


        
1条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 02:51

    You should use utf8mb4 for PDO and your database structures.

    $dsn='mysql:host=example.com;dbname=testdb;port=3306;charset=utf8mb4';
    

    When possible, don't forget to set the character encoding of your pages as well. PHP example:

    mb_internal_encoding('UTF-8');
    mb_http_output('UTF-8');
    

    0 讨论(0)
提交回复
热议问题