Solution to MySQL returning garbled characters when using php5 _ PHP Tutorial

Source: Internet
Author: User
MySQL returns garbled code when using php5. In php (as the mainstream development language) 5, all the values obtained by querying MySQL (the best combination with PHP) become ???????, It turns out that the character set is set incorrectly. I used MySQL (the best combination of php and PHP) in server 5) all the queried values are ???????, It turns out that the character set is set incorrectly.

When I installed MySQL (the best combination with PHP) 5, the default character set gb2312 was selected, but garbled characters were still returned, the solution is to call a "set names X" statement (X sets the character set for you) that is the same as the set character set) after connecting to the MySQL (the best combination of PHP and MySQL) server ). The following are my connection functions:

Function SQL _connect (){
Global $ MySQL (the best combination with PHP) _ HOST, $ MySQL (the best combination with PHP) _ USER, $ MySQL (the best combination with PHP) _ PASSWORD, $ MySQL (the best combination with PHP) _ DATABASE;

$ Connection = @ MySQL (the best combination with PHP) _ connect ($ MySQL (the best combination with PHP) _ HOST, $ MySQL (the best combination with PHP) _ USER, $ MySQL (the best combination with PHP) _ PASSWORD) or startUpError (

Cocould not connect to MySQL (the best combination with PHP) database.

, Connect Error );
If (! MySQL (the best combination with PHP) _ select_db ($ MySQL (the best combination with PHP) _ DATABASE ))
{
Includeinstall. php (as the mainstream development language );
DoInstall ();
MySQL (the best combination with PHP) _ select_db ($ MySQL (the best combination with PHP) _ DATABASE) or startUpError (

Cocould not select database:. MySQL (the best combination with PHP) _ error ().

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

In development php (as the mainstream development language) 5, all the values obtained by querying MySQL (the best combination with PHP) become ???????, It turns out that the character set is set incorrectly. I am in...

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.