I have to insert many data from excel to a table (about 4000 rows ) throught Ajax inside a loop i use :
$query = "INSERT IGNORE INTO ".$params["table"]." (".$colonnes_string.") VALUES (".$row.")";
This query works fine but it insert only 1000 rows of 4000, may be some insert have error why i set IGNORE statement, but it still not insert above 1000 rows.
How can i skip insert error and continue the query ?
Thank you.
请使用INSERT ... ON DUPLICATE KEY UPDATE语法而不是IGNORE这是指向类似问题的链接https://softwareengineering.stackexchange.com/questions/238472/how-to-insert-update-a-large-amount-of -将数据导入mysql-php
You can insert multiple rows with that syntax :
$query = "
INSERT INTO some_table
(column_name)
VALUES
('value'),
('another value'),
('and again'),
...
('a last one');
";
So, you'll have to build the query with all your VALUES
and then INSERT
them all at once.
ie :
// Set the first part of the query with table name and column(s)
$query = "INSERT INTO some_table (some_column) VALUES ";
foreach ($rows as $row) {
// concatenate the query with values in a loop
$query .= "(".$row."),";
}
// replace last comma with semi-column to get the right syntax
$query = substring($query, 0, -1).";";
Hope it helps.
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.