Home > Article > Backend Development > Solution to MySQL returning garbled characters when using PHP 5_PHP Tutorial
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);Could not select database : . MySQL(The best combination with PHP)_error().
, Connect Error);