How to insert 100 records in mysql procedure and loop in MySQL procedure not in PHP?

Solution:
You can build a multi-rowINSERT
in your PHP code. Assuming your data is in$arr
:
$sql = "INSERT INTO yourtable (...column list...) VALUES ";
$vsets = array();
foreach ($arr as $values) {
$vsets[] = str_replace(array(',,', ',,'), ',NULL,', "(" . implode(',', $values) . ")");
}
$sql .= implode(',', $vsets);
echo $sql;
Output:
INSERT INTO yourtable (...column list...)
VALUES (19287,1,1,101,224,0),(19285,0,1,101,2,0),
(19289,1,1,72,23,0),(19290,NULL,1,106,3,0),
(19291,0,1,230,76,0)
Make sure you filter, validate or cast your data, to prevent any non-integers (or any SQL) from being injected into your queries.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: target class [commandmakecommand] does not exist.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.