根据,这不是公认的SQL语法the MySQL manual. 你必须
INSERT INTO MyGuests
(firstname, lastname, email)
VALUES (\'John\', \'Doe\', \'[email protected]\')
但是,这是一个远远超出您的问题范围的扩展,如果您有一个此信息的数组,您可以迭代整个过程来构建SQL字符串。
// The array of information
$guests = array(
array(
\'first_name\' => \'John\',
\'last_name\' => \'Doe\',
\'email\' => \'[email protected]\',
),
array(
\'first_name\' => \'Jane\',
\'last_name\' => \'Doe\',
\'email\' => \'[email protected]\',
),
);
// Build the SQL string
$sql = \'\';
foreach($guests as $g) {
if($sql != \'\') $sql.= \',\';
$sql .= \'("\'. $g[\'first_name\'] .\'", "\'. $g[\'last_name\'] .\'", "\'. $g[\'email\'] .\'")\';
}
if($sql != \'\') {
$sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ". $sql;
}
// $sql now is either empty or full of lots of records to insert.