PHP PDO: charset, set names?

前端 未结 9 905
孤独总比滥情好
孤独总比滥情好 2020-11-22 06:49

I had this previously in my normal mysql_* connection:

mysql_set_charset(\"utf8\",$link);
mysql_query(\"SET NAMES \'UTF8\'\");

Do I need it

9条回答
  •  清歌不尽
    2020-11-22 07:07

    I just want to add that you have to make sure your database is created with COLLATE utf8_general_ci or whichever collation you want to use, Else you might end up with another one than intended.

    In phpmyadmin you can see the collation by clicking your database and choose operations. If you try create tables with another collation than your database, your tables will end up with the database collation anyways.

    So make sure the collation for your database is right before creating tables. Hope this saves someone a few hours lol

提交回复
热议问题