Forum Moderators: coopster

Message Too Old, No Replies

some what complex mysql query

multi row

         

Sarah Atkinson

5:25 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



Can you insert multiple rows with one query?

such as inserting

INSERT INTO table SET
name='John',
favcolor= 'blue';

INSERT INTO table SET
name='Windy',
favcolor= 'purple';

INSERT INTO table SET
name='Michael',
favcolor= 'yellow';

INSERT INTO table SET
name='Peter',
favcolor= 'green';

INSERT INTO table SET
name='Cpt. Hook',
favcolor= 'red';

only do all of these as one call to the DB?
sarah

dmorison

5:48 pm on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




INSERT INTO table (name,favcolor) VALUES ('John','blue'),('Wendy','purple') .... etc.

The only danger is hitting the maximum packet size allowed between PHP and the MySQL server (although it's probably big enough not to be a worry - 16MB or something). That said, it's probably not a good idea to go reading in a massive text file and building 1 SQL query from it!