是否可以使用 php 在 mysql 中插入多个查询
Is it possible to insert multiple queries in mysql using php
我想在 mysql 中使用 php 形式在不同的表中插入多个查询。
喜欢是否可以使用 INSERT ALL 命令或类似的命令。
为我提供解决问题的最佳途径
您可以像这样添加更多查询:
INSERT INTO `Table` (`column`) VALUES ('theValue');
INSERT INTO `Table` (`column`) VALUES ('anotherValue');
INSERT INTO `Table` (`column`) VALUES ('yetAnotherValue');
INSERT INTO `Table` (`column`) VALUES ('theVal');
您可以根据需要添加任意数量的查询,方法是使用 ;
分隔它们
如果您指的是批量插入,请按照下面给出的示例进行操作。
CREATE TABLE example (
example_id INT NOT NULL,
name VARCHAR( 50 ) NOT NULL,
value VARCHAR( 50 ) NOT NULL,
other_value VARCHAR( 50 ) NOT NULL
)
INSERT INTO example
VALUES
(100, 'Name 1', 'Value 1', 'Other 1'),
(101, 'Name 2', 'Value 2', 'Other 2'),
(102, 'Name 3', 'Value 3', 'Other 3'),
(103, 'Name 4', 'Value 4', 'Other 4');
或
如果你想插入数据到多个table,那么下面给出的解决方案是正确的,为每个table写查询。
注意:插入语句只写一次,我们重复它的值。
我想在 mysql 中使用 php 形式在不同的表中插入多个查询。
喜欢是否可以使用 INSERT ALL 命令或类似的命令。
为我提供解决问题的最佳途径
您可以像这样添加更多查询:
INSERT INTO `Table` (`column`) VALUES ('theValue');
INSERT INTO `Table` (`column`) VALUES ('anotherValue');
INSERT INTO `Table` (`column`) VALUES ('yetAnotherValue');
INSERT INTO `Table` (`column`) VALUES ('theVal');
您可以根据需要添加任意数量的查询,方法是使用 ;
如果您指的是批量插入,请按照下面给出的示例进行操作。
CREATE TABLE example (
example_id INT NOT NULL,
name VARCHAR( 50 ) NOT NULL,
value VARCHAR( 50 ) NOT NULL,
other_value VARCHAR( 50 ) NOT NULL
)
INSERT INTO example
VALUES
(100, 'Name 1', 'Value 1', 'Other 1'),
(101, 'Name 2', 'Value 2', 'Other 2'),
(102, 'Name 3', 'Value 3', 'Other 3'),
(103, 'Name 4', 'Value 4', 'Other 4');
或
如果你想插入数据到多个table,那么下面给出的解决方案是正确的,为每个table写查询。
注意:插入语句只写一次,我们重复它的值。