Getting weird characters when fetching value in mysql database

前端 未结 3 1997
执念已碎
执念已碎 2020-12-21 14:03

I\'m getting this kind of result in my database ’ everytime i\'m typing this character

I already use mysql_query(\'SET CHARACTER

3条回答
  •  攒了一身酷
    2020-12-21 14:40

    I notice that you're running this query... mysql_query('SET CHARACTER SET utf8');
    Try changing that to this...

    mysql_query("SET NAMES 'utf8'");

    That should ensure that the connection is UTF-8.

    Also try going through the list of items on this article... http://blog.loftdigital.com/blog/php-utf-8-cheatsheet
    This lists the steps that are needed to make sure you're using UTF-8 from front to back in your site/application but in summary:

    • Check you've got PHP's mbstring extension and you have mb_internal_encoding('UTF-8'); set in your script.
    • Make sure you're running this MySQL query after connecting to your database mysql_query("SET NAMES 'utf8'"); which ensures the connection is UTF-8.
    • Set the HTTP header of your output... header('Content-type: text/html; charset=UTF-8');. This doesn't seem to be needed if you've set mb_internal_encoding() above but useful for debugging
    • Make sure the output encoding of your HTML page is set...

提交回复
热议问题