Why do i have to use set_charset(“utf8”) even though everything is utf-8 encoded? (MySQLi-PHP)

非 Y 不嫁゛ 提交于 2020-01-04 01:53:22

问题


My table's collation is utf8_general_ci.

My pages are encoded with UTF-8 (without BOM).

Within my pages, my Equiv meta tag sets character set to utf8

My data has Turkish characters in it.

When i output them, it's not showing them as it should be but when i do $db->set_charset("utf8");, it works.

Why do i have to use $db->set_charset("utf8"); even though everything is utf-8 encoded?


回答1:


The data is stored as UTF-8 in MySQL, but the PHP's client connection collation is not. Which is why you have to use set_charset in PHP for the DB connection.

Update

php.ini : default_charset utf-8
.htaccess : AddDefaultCharset utf-8



来源:https://stackoverflow.com/questions/3571752/why-do-i-have-to-use-set-charsetutf8-even-though-everything-is-utf-8-encoded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!