Why can't mysql insert data? -Php Tutorial

Source: Internet
Author: User
Tags mysql insert
Why can't mysql insert data? After AppServ is installed, mysql is used for the first time. There is no graphical interface. the operations on "MySql Command Line Client" are as follows:
========================================================== ========================================================== ======
Mysql> create database cars;
Query OK, 1 row affected (0.00 sec)

Mysql> use cars;
Database changed
Mysql> create table cars (id int, xm char (8), h char (8), vin char (20 ));
Query OK, 0 rows affected (0.06 sec)

Mysql> insert into cars (id, xm, h, vin) values (1, 'Lian Dongfang ', 'Yu A5F568', 'ldc666l2980790000 ');
Query OK, 1 row affected, 1 warning (0.02 sec)

Mysql> select * from cars;
+ ------ + ---------- + ------------------- +
| Id | xm | h | vin |
+ ------ + ---------- + ------------------- +
| 1 | Yu A5F568 | LDC666L2980790000 |
+ ------ + ---------- + ------------------- +
1 rows in set (0.02 sec)

Mysql> select xm from cars;
+ ------ +
| Xm |
+ ------ +
|
+ ------ +
1 rows in set (0.00 sec)

Mysql> update cars set xm = 'Lian 'where id = 1;
Query OK, 0 rows affected, 1 warning (0.01 sec)
Rows matched: 1 Changed: 0 Warnings: 0

Why cannot I set the value of the xm field? Why cannot I update it? Thank you ~~~


Reply to discussion (solution)

Mysql> \ W
Show warnings enabled.
Mysql> update cars set xm = 'Lian Dongfang 'where id = 1;
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

Warning (Code 1366): Incorrect string value: '\ xC1 \ xAE \ xB6 \ xAB \ xB7 \ xBD' for colu
Mn 'xm 'at row 1
Mysql> _

Here we can see that the length of the inserted data is 6 bytes, but the length is not 8 bytes. why is it wrong?


Mysql> set names UTF-8;
ERROR 1115 (42000): Unknown character set: 'utf'
Mysql> set names utf8;
Query OK, 0 rows affected (0.00 sec)

Mysql> update cars set xm = 'Lian 'where id = 1;
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

Warning (Code 1366): Incorrect string value: '\ xC1 \ xAE' for column 'xm 'at row 1

Mysql> _


I still can't. I'm in a hurry ~~~


Mysql> insert into cars (id, xm, h, vin) values (1, 'Lian Dongfang ', 'Yu A5F568', 'ldc666l298079
0000 ');
Query OK, 1 row affected (0.00 sec)

Mysql> select * from cars;
+ ------ + -------- + ---------- + ------------------- +
| Id | xm | h | vin |
+ ------ + -------- + ---------- + ------------------- +
| 1 | Lian Dongfang | Yu A5F568 | LDC666L2980790000 |
+ ------ + -------- + ---------- + ------------------- +
1 row in set (0.00 sec)


What operating system are you using?

At the beginning of learning php, too difficult to configure, the next appserv-win32-2.6.0.exe directly installed.

Is it unreasonable to install it?

Windows 7 OS is installed on the computer ~~~

Run set names gbk first.

Run set names gbk first.

Some people just checked the information and used it: set names utf8; not available after testing,

But "set names gbk;" is indeed successful. thank you very much!

Can you briefly explain why?

Your #1 content is only visible after I reply to #3. Otherwise, it will be explained at the beginning.

\ XC1 \ xAE \ xB6 \ xAB \ xB7 \ xBD is the gbk internal code of Lian Dongfang.
However, he reported an error. This indicates that the default character set of your database is not latin1 or gbk.
So the Chinese error can only be utf8 (very few people with UCS-2, even it does not matter)

If you insert gbk characters into the utf8 field, an error is returned.
Therefore, set names gbk to notify mysql that the gbk character is used now.

Why did "yu" not report an error?
This depends on how UTF-8 is encoded:
U + 007F 0 xxxxxxx
U + 07FF 110 xxxxx 10 xxxxxx
U + FFFF 1110 xxxx 10 xxxxxx 10 xxxxxx
U + 1 FFFFF 11110xxx 10 xxxxxx 10 xxxxxx 10 xxxxxx
U + 3 FFFFFF 111110xx 10 xxxxxx 10 xxxxxx 10 xxxxxx 10 xxxxxx
U + 7 FFFFFFF 1111110x 10 xxxxxx 10 xxxxxx 10 xxxxxx 10 xxxxxx

Yu's gbk binary internal code is 11010100 10100101
It is in line with the U + 07FF encoding rules, so he will not report an error

Thank you for your patience ~~~

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.