php INSERT INTO语法问题

时间:2015-03-24 21:02:24

标签: php mysql syntax

INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES (50, ‘Archival Information’, ‘B479’, 4321, ‘Robin’);

这样可行,但事实并非如此:

INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES (50, ‘Archival Information’, ‘B479’, 4321, ‘Robin’),
(51, ‘Information Retrieval’, ‘B431’, 4322, ‘Sheela’),
(52, ‘Information Organization’, ‘B410’, 4323, ‘Craig’),
(53, ‘Information Policy’ ‘B204’, 4324, ‘Michael’),
(54, ‘Information Management’, ‘B219’, 4331, ‘Chris’),
(55, ‘Information Security’, ‘B225’, 4332, ‘Steve’),
(56, ‘Information Technology’, ‘B435’, 4333, ‘Arthur’),
(57, ‘Information Design’, ‘B300’, 4334, ‘Amy’),
(58, ‘Health Informatics’, ‘B428’, 4330, ‘Rav’),
(59, ‘Information Ethics’, ‘B356’, 4320, ‘Simon’);

有什么问题?我已经在线检查了语法,这就是我注意到输入正确语法的方式。

4 个答案:

答案 0 :(得分:3)

除了第一个

之外,您的单引号不正确
  BT你的sql服务器很重要只有mssql 2008或更新和mysql   4.1或更新版本支持使用逗号分隔插入多个值。

正确的sql查询:

INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES (50, 'Archival Information', 'B479', 4321, 'Robin'),
(51, 'Information Retrieval', 'B431', 4322, 'Sheela'),
(52, 'Information Organization', 'B410', 4323, 'Craig'),
(53, 'Information Policy', 'B204', 4324, 'Michael'),
(54, 'Information Management', 'B219', 4331, 'Chris'),
(55, 'Information Security', 'B225', 4332, 'Steve'),
(56, 'Information Technology', 'B435', 4333, 'Arthur'),
(57, 'Information Design', 'B300', 4334, 'Amy'),
(58, 'Health Informatics', 'B428', 4330, 'Rav'),
(59, 'Information Ethics', 'B356', 4320, 'Simon');

@exussum警告我关于mysql的版本,所以, 我编辑了受支持的mysql版本号5.5到4.1谢谢。

答案 1 :(得分:0)

您在第4行('Information Policy''B204'之间)缺少逗号。纠正这个后,它对我有用。

答案 2 :(得分:-1)

VALUES (50, 'Archival Information', 'B479', 4321, 'Robin'),
(51, ‘Information Retrieval’, ‘B431’, 4322, ‘Sheela’),

你的第一行使用了单引号,而你的第二行使用了反引号。

在MySQL中,反引号是identifier quote,意味着它将内部视为标识符。例如一个表名。常规报价被视为要插入的数据。

转换病房第2行,使用'代替'''

http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

答案 3 :(得分:-2)

INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES 
    (50, 'Archival Information', 'B479', 4321, 'Robin'),
    (51, 'Information Retrieval', 'B431', 4322, 'Sheela'),
    (52, 'Information Organization', 'B410', 4323, 'Craig'),
    (53, 'Information Policy', 'B204', 4324, 'Michael'),
    (54, 'Information Management', 'B219', 4331, 'Chris'),
    (55, 'Information Security', 'B225', 4332, 'Steve'),
    (56, 'Information Technology', 'B435', 4333, 'Arthur'),
    (57, 'Information Design', 'B300', 4334, 'Amy'),
    (58, 'Health Informatics', 'B428', 4330, 'Rav'),
    (59, 'Information Ethics', 'B356', 4320, 'Simon');