Sure, MySQL lets you do this:
INSERT INTO your_table VALUES
('text', 'more text', 4, 12),
('text', 'more text', 4, 12),
('text', 'more text', 4, 12),
('text', 'more text', 4, 12);
This single insert query adds four rows to the table 'your_table'. Also,
they inserted rows don't have to be identical, you can do this instead if
you like:
INSERT INTO your_table VALUES
('some text', 'more text', 4, 12),
('other stuff', NULL, 6, 3),
('stuff', 'blah blah', 55, 0),
('blah', '', 0, 0);
So if you have an insert statement in a loop that does something like this:
for ($i=0; $i<100; $i++)
{
mysql_query('INSERT INTO your_table VALUES (0,1,2,3)');
}
You could replace it with this:
$first = true;
$query = 'INSERT INTO your_table VALUES';
for ($i=0; $i<100; $i++)
{
if (!$first) $query .= ', ';
$query .= ' (0,1,2,3)';
$first = false;
}
mysql_query($query); // only one insert statement
Hope that helps,
Patrick Emond
- Original Message -
From: "Leif K-Brooks" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, May 31, 2002 3:12 PM
Subject: [PHP-DB] Mutiple inserts with one query?
> Is there a way to insert multiple identical rows in one mysql query?
> I'm using a looped query right now, which uses more server load than it
> should... Thanks!
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php