Use PHP 5 o'clock MySQL return garbled solution

Source: Internet
Author: User
Tags character set connect mysql query mysql database

In the use of PHP 5, the value obtained through the MySQL query all become '??????? ', the original character set is wrong.

I installed MySQL 5 o'clock, has chosen the default character set for gb2312, but still return garbled, the solution is to connect to the MySQL server, call a set of the same set names X statement (x for you set the character set). Here's my connection function:

function Sql_connect () {
Global $MYSQL _host, $MYSQL _user, $MYSQL _password, $MYSQL _database;

$connection = @mysql_connect ($MYSQL _host, $MYSQL _user, $MYSQL _password) or startuperror (' <p>could not connect to MySQL database.</p> ', ' Connect Error ');
if (!mysql_select_db ($MYSQL _database))
Include ' install.php ';
DoInstall ();
mysql_select_db ($MYSQL _database) or startuperror (' <p>could not select DATABASE: '. Mysql_error (). ' </p> ', ' Connect Error ');
Sql_query (' Set names "gb2312"); Sql_query is a custom execution query function, the key is this statement
return $connection;

Related Article

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: 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.