-->

Reading signs like č ć đ š ž from MySql database

2020-02-13 05:33发布

问题:

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.