upload and auto insert to sql
Hi There people
I sure this is gonna be something easy but I have pulled what little hair out that I had left over the past couple of weeks... So some help would be appreciated..
Situation is as follows..
Auto sent to my server daily are approx 100 diff files all titled... *****-logfile.sql
Currently received as follows. Crude and no error checking added at this moment............. but thats another matter.
$uploaddir = "filelist/";
$file = $uploaddir . $_FILES['uploadfile']['name'];
The files all have the format of....
DELETE FROM `webuserdata` WHERE `NickName` = "OkiesPlace";
Insert into webuserdata (NickName, FileStatus, Correspondent, Period, FileName, Series, Files) values ('OkiesPlace','Sent','Enforcer','May 2008','CB30001-05 - Spears Britney - From The Bottom Of My Broken Heart.zip','CB','1');
These could contain from 1 to 5000 Insert lines.
At this moment, I manually insert each file and then delete.
What I would like to do is...
As file is uploaded it should be auto run to sql and when completed then be deleted.
I assume somehow I gotta include the connect code to the database and run the query.
Should there be an error on insert, which does occasionally happen. Would like it to write to an error file with the offending line number which caused the error.
All that sounds very easy HaHa
But certainly not been so for me.
Help Please and thanks
in that format can't you just set up a cron job to handle the task with ease?
You could explode them on the semi-colons to process each query:
$contents = trim(file_get_contents($file), ";\t\n\r ");
$queries = explode(';', $contents);
foreach($queries as $query)
if(mysql_query($query) == false)
error_log($file . ': ' . mysql_error() . "\n" . $query);
Thanks for responses.
Firstly regarding cron job.
I do have access to cron.
However, this becomes a bigger nightmare of understanding than does php HaHa
My understanding is that i need a script for the cron to execute.
If you could assist with explanation, I would be grateful.
With regard to explode..
I am just as lost, where would i add the script you have shown.. and how would i insert the connect code.
Thanks again for your help, but bit more required please.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)