PHP 插入语法问题


php INSERT INTO issue with 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’);

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

除了第一个引号外,您的单引号不正确

顺便说一句,您的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,谢谢。

您在值的第四行(在 'Information Policy''B204' 之间(缺少逗号。纠正此问题后,它对我有用。

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

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');