Php connection to the SQL file encoding problem. The last time the code was fixed, another problem occurred.

Source: Internet
Author: User
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 ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.