Home  >  Article  >  Backend Development  >  Solution to MySQL returning garbled characters when using PHP 5_PHP Tutorial

Solution to MySQL returning garbled characters when using PHP 5_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:32:20996browse

When using php(as the current mainstream development language) 5, through MySQL(the best combination with PHP) all the values ​​obtained from the query become??? ????, it turns out that the character set is set wrong.

When I installed MySQL (the best combination with PHP) 5, I selected the default character set as gb2312, but it still returned garbled characters. The solution is to connect to MySQL (The best combination with PHP) After the server, call a "set names X" statement that is the same as the set character set (X is the character set you set). The following is my connection function:

function sql_connect() {
global $MySQL(The best combination with PHP)_HOST, $MySQL(With PHP The best combination)_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(

Could not connect to MySQL(and 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 current mainstream development language);
doInstall();
MySQL(The best combination with PHP)_select_db($MySQL(The best combination with PHP)_DATABASE) or startUpError(

Could not select database : . MySQL(The best combination with PHP)_error().

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508723.htmlTechArticleIn using PHP (as the current mainstream development language) 5, through MySQL (the best combination with PHP combination) The values ​​obtained from the query all become ???????. It turns out that the character set is set incorrectly. I'm installing...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn