Jump to content


inputing multipul data at once into a database

  • Please log in to reply
1 reply to this topic

#1 spires

  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 01 September 2006 - 11:41 AM


Does any know how to add more than one row into your database at the same time?

I'm guessing it would be some kind of four loop that keeps looping over the INSERT untill
all the data is in.

Any ideas please
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:

#2 pmeasham

  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 01 September 2006 - 03:35 PM

you can do this with sql:

INSERT INTO `table` VALUES ('data1a','data1b'),('data2a','data2b'),('data3a','data3b')

You can do this with php using multi database querys as well, however I'd look into using a database abstraction layer.
eg from pears:

$sth = $db->prepare('INSERT INTO numbers VALUES (?, ?, ?)');
$alldata = array(array(1, 'one', 'en'),
                 array(2, 'two', 'to'),
                 array(3, 'three', 'tre'),
                 array(4, 'four', 'fire'));
$res =& $db->executeMultiple($sth, $alldata);

see: http://pear.php.net/package/DB

Peter Measham
Unique IQ Ltd

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users