I have little problem and i have no idea how to make it work. I want to make query that inserts rows by number. Example: If posted number is 8 then query adds 8 rows.
Any idea how to do it with pdo?
SQL
INSERT INTO
foo(bar,baz)
VALUES
("val1", "val2"),
("val1", "val2"),
("val1", "val2"),
("val1", "val2"),
("val1", "val2"),
("val1", "val2"),
("val1", "val2"),
("val1", "val2")
;
PHP
//Insert Statement
$sql = 'INSERT INTO foo(bar,baz) VALUES ';
//Values ("val1", "val2"),("val1", "val2"),("val1", "val2"),..
for ($i = 0; $i <= 8; $i++) {
$sql.= '("val1", "val2"),';
}
//Remove last Comma, and set ";" at the end.
$sql = rtrim($sql, ",") . ';';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.