Reading signs like č ć đ š ž from MySql database

眉间皱痕 提交于 2019-11-28 06:25:42

问题


I have problems reading signs 'č', 'ć', 'đ', 'š', 'ž' from MySQL database.

I have tried few suggestions that I found on the internet, but none worked. I am looking for correct combination of charset in the database and in PHP file. So far I have always used UTF.


回答1:


Use SET CHARACTER SET 'utf8' before querying any data.

http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html




回答2:


  • Set table and db charset, collation, etc. to utf8_general_ci

  • After establishing connection from php, be sure to do SET NAMES UTF8. That step is very important.

  • Make sure you saved all PHP files using utf-8 encoding (that was common cause several years ago)

  • <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

I'm from Slovenia, where we use these 'special chars', and believe me, this is our everyday problem ;)




回答3:


Try to do this before reading

SET character_set_client='utf8'
SET character_set_results='utf8'
SET collation_connection='utf8_general_ci'



回答4:


You can add simply in your PHP (in Writting and Reading):

$con = mysqli_connect(...);
mysqli_set_charset($con,"utf8");

After having your table set as ut8 for default charset.



来源:https://stackoverflow.com/questions/5057048/reading-signs-like-%c4%8d-%c4%87-%c4%91-%c5%a1-%c5%be-from-mysql-database

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