PHP + MYSQL garbled

Source: Internet
Author: User
PHP + MYSQL garbled problem my mysql code is utf8_bin
Page encoding
Zend is used for development, and the PHP page encoding UTF-8 is also set in zend.
However, the queried data is garbled on the front-end page.
After mysql_query ("set names 'gb2312 '") is executed in the PHP file connected to the database, the queried data is displayed normally. The front-end page is garbled to retrieve database data. I hope our predecessors can give some advice.
My front-end page is written in Dreamweaver


Reply to discussion (solution)

What encoding is your program file?

Is the field encoding in your mysql database and table set to utf8?

What encoding is your program file?
I set the php file to UTF-8 in zend software. Do you know the encoding of the program file?

Is the field encoding in your mysql database and table set to utf8?
It is set to UTF8_bin encoding. Later, I deleted the database and created a new database. when I was creating the database, I set it to utf8_bin encoding. I also read the table and Field Encoding, both of which are utf8_bin.

I deleted the database and re-built the project in zend, and set the page to UTF-8.
I printed the data in the file connecting to the database, and it showed garbled characters. Add mysql_query ("set names 'gb2312'") under the database connection statement. The printed data is in Chinese, but the data is retrieved from the front-end page. It becomes garbled again.

If the database is deleted, the database has no content.
How can you query data?
In other words, how do you put data into the database?

Add mysql_query ("set names 'gb2312'") under the database connection statement to print all the data in Chinese.
Indicates that the program file you run is gbk encoded, not UTF-8

If the database is deleted, the database has no content.
How can you query data?
In other words, how do you put data into the database?
I deleted the database and re-built it. The data was re-added by executing SQL statements.

Add mysql_query ("set names 'gb2312'") under the database connection statement to print all the data in Chinese.
Indicates that the program file you run is gbk encoded, not UTF-8
How can I modify the code of a program file? Isn't it modified in zend?

I added a mysql_query ("set names 'gb2312'") under the database connection statement. I changed gb2312 to utf8 and the front-end page would display Chinese characters normally. I previously changed to UTF-8, and the front-end page displays garbled characters. Thank you for your help!

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.