PHP inserts Chinese characters into MYSQL.

Source: Internet
Author: User
PHP inserts Chinese characters into MYSQL. if you have any questions, I am a newbie. if you insert Chinese characters into MYSQL through PHP, you cannot insert them. My code is as follows, the page and MYSQL character set are all UTF-8 $ dbc = mysqli_connect ('localhost', 'root', 'roo PHP inserts Chinese into MYSQL, there is a problem
Hello everyone, I am a newbie. I can't insert Chinese characters into MYSQL through PHP.
My code is as follows, the page and MYSQL character set are all UTF-8

$ Dbc = mysqli_connect ('localhost', 'root', 'root', 'aliendatabase ')
Or die ('error connecting to MySQL server .');

$ Query = "insert into aliens_abduction (other) VALUES ('hao ')";

$ Result = mysqli_query ($ dbc, $ query)
Or die ('error querying database .');

Mysqli_close ($ dbc );

In addition, Chinese characters are inserted on the MYSQL client. the following error occurs:

Mysql> insert into a values ('hao ');
ERROR 1366 (HY000): Incorrect string value: '\ xBA \ xc3' for column 'A' at row 1

The MYSQL character set is as follows:
Mysql> show variables like '% char % ';
+ -------------------------- + --------------------- +
| Variable_name | Value |
+ -------------------------- + --------------------- +
| Character_set_client | utf8 |
| Character_set_connection | utf8 |
| Character_set_database | gbk |
| Character_set_filesystem | binary |
| Character_set_results | utf8 |
| Character_set_server | utf8 |
| Character_set_system | utf8 |
| Character_sets_dir | C: \ Program Files \ MySQL Server 5.5 \ share \ charsets \ |
+ -------------------------- + --------------------- +


------ Solution --------------------
$ Query =

Previously added

Mysql_query ("set names 'utf8 '");
------ Solution --------------------
The main solution!
Run the command in the dos window. if so, run the set names gbk command before insert;

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.