and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi, this is my first post on this forum. I am trying to add large amounts of data to an sql database using php. The fields being added have 3 columns and anywere from 1,000 to 10,000 rows. The primary key for each field is set to auto increment. The way I am doing it right now is this:
$i = 0;
foreach($un as $val){
mysql_query("INSERT INTO database(un,pw,login) VALUES('$val','$pw[$i]','$login[$i]')") or die(mysql_error());
$i++;
}
the $i variable is just to keep the $pw and $login values the same as the $un values. This of course does one mysql_query per array element in the $un array. I am fairly new to sql/php and am not sure if there is a better way to enter large amounts of data. This method takes a long time to execute, if anyone knows how I could speed the process up I would greatly appreciate it.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
MySQL supports what are referred to as extended inserts, where multiple rows can be inserted in the same query. There are various length limitations but you can pool many rows before those become a problem. You may also want to look into having MySQL import the data from a file.
The only reason I didn't put any warnings in my post is because I knew you would violate them anyway. Ok, now that the fun is over, sahll we get back on track?