PHP MySQL Chinese garbled

Source: Internet
Author: User

Windows MySQL loaded SQLyog-32 bit
INSERT into USER VALUES (' 123 ', ' 123 ', ' Purple Xuan ');
Database query found to be garbled:
Probably because the default format for MySQL is latin1, it is recommended that you create a new database (which is not a reload) and change the encoding to GBK.
Fix MySQL garbled.
PHP connection MySQL
<?php $db _host= ' localhost ';  $db _database= ' work ';  $db _username= ' root ';  $db _password= ' yubing '; $connection =mysql_connect ($db _host, $db _username, $db _password);//Connect to the database mysql_query ("Set names ' GBK '");//Code conversion if (!$ Connection) {Die ("could does connect to the Database:</br>". Mysql_error ());//Diagnostic connection Error} $DB _selecct=mysql_select _db ($db _database);//Select Database if (! $db _selecct) {die ("could not to the database</br>". Mysql_error ());} $query = "select * from user where username = ' $user _name '";//Build Query Statement $result =mysql_query ($query);//Execute Query if (! $result) {  Die ("Could not to the database</br>". Mysql_error ()); }//Array mysql_fetch_row (resource $result);  while ($result _row=mysql_fetch_row ($result))//Check out the result and display {$username = $result _row[0];  $password = $result _row[1];  $chname = $result _row[2];  echo "<tr>";  echo "<td> $username </td>"; echo "<tr>";  echo "<td> $password </td>"; echo "<tr>";  echo "<td> $chname </td>"; echo "<tr>";  echo "</tr>"; } mysql_close ($connection);//close Connection?>
Here's the mysql_query ("Set names GBK");
Note that MySQL and PHP code here to unify, the page display garbled solution

PHP MySQL Chinese garbled

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.