PHP inserted into MySQL Chinese, there is a problem
Hello everyone, I am a novice, in the PHP to MySQL into the Chinese is, is not plugged in AH.
My code is as follows, the page and the 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 (' good ')";
$result = Mysqli_query ($dbc, $query)
Or Die (' Error querying database. ');
Mysqli_close ($DBC);
In addition, the MySQL client inserted Chinese characters also have a problem, the error is as follows
Mysql> INSERT into a values (' good ');
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\mysql Server 5.5\share\charsets\ |
+--------------------------+---------------------+
------Solution--------------------
$query =
Before adding
mysql_query ("SET NAMES ' UTF8 '");
------Solution--------------------
The landlord is the solution!
You are executing under DOS window, if so, execute the set names GBK before insert.
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.