PHP Connection SQL file encoding problem, the last patch, and problems, solve

Source: Internet
Author: User
Tags php database
I am using PHP database connection, when the data is stored in the problem, but with PHP to the data encoding method has been modified,
===========================================
Iconv ("Utf-8", "GBK", $array [2])
===========================================
The deposit is correct, but is to take out the data when the problem, think again with the original way back, but no way to change back ...
When I take Chinese and print it to a webpage, it becomes "??" ”... Want to be the problem of data encoding, just do not know how to unify
My PHP code is to use the UTF8 database is also UTF8, is not and the browser encoding is also related? ...
I have the error page below.


Reply to discussion (solution)


This is the problem, would have output "welcome Zhang San" and the like, but it became "welcome??" ”...
The last time the problem was stored in the database when the Chinese deposit is "?? "This time it was taken out to become this ...
Tangled Ah ... Is there any way to unify it?

mysql_query ("Set names UTF8"); Add this sentence before executing a query
Prevent page output garbled can be added at the beginning of the PHP file: header ("Content-type:text/html;charset=utf-8");

$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 the SQL statement, add mysql_query (' Set names UTF8 '), you can solve the premise is that the data is Chinese, can not be garbled!

This is very your database coding problems, you go into the MSYQL database to see, there is mysql_query ("Set names UTF8"), and then there is the Web page BOM problem. If you can't solve it, just put it on the hook.

Thank you, with everyone's method finally solved, thank you very much ha ~
mysql_query (' Set names UTF8 ');
This is the statement plus go to the good ~

  • Related Article

    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.