Php connection to the SQL file encoding problems, the last installation, and related problems, to solve

Source: Internet
Author: User
Tags php database
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, I used php to modify the data encoding method. iconv (UTF-8, gbk, $ array [2]) php is connected to the SQL file encoding problem. The last time I installed it, there was another problem, solution
I am using a php database connection, and there is a problem when storing data, but I used php to modify the data encoding method,
========================================================== ===
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.

Php database


------ Solution --------------------
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 ");
------ Solution --------------------

[Email protected] _ 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!
------ Solution --------------------
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.

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.