Solution to MySQL return garbled characters when php5 is applied

Source: Internet
Author: User
In the application PHP5, all the values obtained through MySQL Query become '??????? '. It was originally a character set error. When installing MySQL 5, I have selected the default character set gb2312, but garbled characters are still returned. the solution is to connect to the MySQL server.

In PHP 5, all the values obtained through MySQL Query become '??????? '. It was originally a character set error.

When I installed MySQL 5, the default character set is gb2312, but garbled characters are still returned. the solution is to connect to the MySQL server, call a 'set names x' statement similar to the character set ). The following are my connection functions:

Function SQL _connect (){
Global $ MYSQL_HOST, $ MYSQL_USER, $ MYSQL_PASSWORD, $ MYSQL_DATABASE;

$ Connection = @ mysql_connect ($ MYSQL_HOST, $ MYSQL_USER, $ MYSQL_PASSWORD) or startUpError ('

Cocould not connect to MySQL database.

', 'Connect error ');
If (! Mysql_select_db ($ MYSQL_DATABASE ))
{
Include 'Install. php ';
DoInstall ();
Mysql_select_db ($ MYSQL_DATABASE) or startUpError ('

Cocould not select database: '. mysql_error ().'

', 'Connect error ');
}
SQL _query ('set names' gb2312 ''); // SQL _query is a custom query function. The key is this statement.
Return $ connection;
}

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.