I have an array with more than 134675+ values, I need to insert them to my mySQL table. I know all the things needed in this to work with PHP and mySQL data insertion. Is there a fast method that would let me insert all these values on a remote server within 30-60 seconds? because when i am trying it with the foreach method, the page is timing out. The remote server is not allowing DB connections to persist for more than 60 seconds. I dont know why. So please help me with a fast logic.
Here is some code i tried:
foreach($array as $value)
{
$sql="insert into collected values('".$value."')";
$res=mysql_query($sql);
//then some extra code.
}
NOTE
I dont have so many access privileges on the server. My DB account can only insert values and nothing more than that. And its a constraint on the mySQL DB. I cannot use CSV or any other thing.
You could include in your loop the
mysql_ping()function. This function checks to make sure that the connection is open, and if it is not, it re-connects.Using your own example, you could do something like:
Edit: It should be noted that according to the docs, after MySQL 5.0.14, PHP does not automatically reconnect. If you use a newer version of MySQL you will have to put in your own connection logic, maybe like this (I haven’t tested):