www.webdeveloper.com
Results 1 to 4 of 4

Thread: upload and auto insert to sql

  1. #1
    Join Date
    Jun 2008
    Posts
    2

    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.

    <?php
    $uploaddir = "filelist/";
    $file = $uploaddir . $_FILES['uploadfile']['name'];
    move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)
    ?>

    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

    Keith

  2. #2
    Join Date
    Dec 2005
    Posts
    193
    in that format can't you just set up a cron job to handle the task with ease?

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,614
    You could explode them on the semi-colons to process each query:
    PHP Code:
    <?php
    $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);
       }
    }
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Jun 2008
    Posts
    2
    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.

    Cheers
    Keith

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles