Php connection to the SQL file encoding problem. The last time I installed it, there was another problem. I used php to solve the problem. when I saved the data, I encountered a problem, however, the data encoding method was modified using php,
========================================================== ===
Iconv ("UTF-8", "gbk", $ array [2])
========================================================== ===
The deposit is correct, but there is a problem when the data is taken out. I want to use the original method to change it back, but there is no way to change it back...
When reading Chinese characters and printing them to webpages, they all become "?"... I think it's about data encoding, but I don't know how to unify it.
My PHP code uses the utf8 database and the utf8 database. is it also related to the browser code ?...
Below is my error page.
Reply to discussion (solution)
This is a problem. I would have output "Welcome to James", but it turned into "Welcome ??"...
The last problem was that when I saved the database, the Chinese character was saved as "?". This is how it is retrieved...
Tangle... is there any way to unify it ?..
Mysql_query ("set names utf8"); // add this sentence before executing the query
To prevent page output garbled characters, add header ("content-type: text/html; charset = utf-8") at the beginning of the PHP file line ");
$ Link = @ mysql_connect (HOST, USER, PASS) or die ("database connection failed"); mysql_select_db (DBNAME, $ link); mysql_query ('set names utf8 '); $ SQL = "select * from users where username = '{$ username}' and state = 1"; $ result = mysql_query ($ SQL, $ link );
Before sending an SQL statement, add mysql_query ('set names utf8'); to solve the problem, provided that the data contains Chinese characters and cannot contain garbled characters!
This is a problem with your database code. you can check it in the msyql database, and mysql_query ("set names utf8"). then there is the bom problem on the web page. Paste it out if it cannot be solved.
Thank you for your solution. thank you very much ~
Mysql_query ('set names utf8 ');
That is, simply add this statement ~