View Full Version : instert multiple records
GO ILLINI
08-04-2007, 07:01 AM
What would be the best way to insert multiple(20-50) records at once with php. Should i just run multiple queries? or is there a way to do it in one query?
thanks,
-Adam
Fumigator
08-05-2007, 01:21 AM
You can do
INSERT INTO tableName
VALUES
(x, x, x)
,(x, x, x)
,(x, x, x)
StupidRalph
08-05-2007, 04:51 AM
^^thats my preferred method...
Using a loop to create an array and then using implode to build the string and then run the query one time.
An example froma previous post.
$wordChunks = array('FOSS312 BLK26', 'FOSS805 BEI26', 'FOSS311 BLK26');
$wordChunks = implode("','", $wordChunks);
//echo $wordChunks;
$sql = "UPDATE products SET products_store='some value' WHERE products_model IN ('" .$wordChunks."');";
echo $sql;
I simply used implode() to add the comma and single quotes. I hardcoded the outer single quotes. You should be able how to do it from here.
http://www.codingforums.com/showthread.php?t=118515
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.