+ Reply to Thread
Results 1 to 3 of 3

Thread: LOAD DATA LOCAL INFILE help...

  1. #1
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    LOAD DATA LOCAL INFILE help...

    I've done quite a bit of reading on this but the subject is fraught with pitfalls.

    I need to import data from a local csv file and have created the following code (adds to existing data).

    <?php
    require_once('Connections/freecrm.php');

    mysql_select_db($database_freecrm, $freecrm)
    or die("Could not open database");

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    $varfilepath=$_POST['filepath'];
    $sql =
    "
    LOAD DATA LOCAL INFILE '$varfilepath'
    INTO TABLE TEST
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '\"'
    LINES TERMINATED BY '\n'
    IGNORE 1 LINES
    ";
    $result = mysql_query($sql)
    or die ("Could not import data.");
    }
    ?>

    In the body, I have a form with 1 field (the file path), 1 hidden field to fulfil the "if" criteria and a submit button.

    But I'm getting the response "Could not import data." which means I'm getting the connection but for some reason, it aint working!

    Have I got a simple Syntax problem here or am I missing the point?

    The page is currently at www.freecrm.x10hosting.com/test.php
    Edit:
    Does anyone have any idea what I'm on about?
    Last edited by freecrm; 09-11-2008 at 02:08 PM. Reason: Automerged Doublepost

  2. #2
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: LOAD DATA LOCAL INFILE help...

    Try to use mysql_error() to know more about the error mysql encounters.
    Real programmers don't document their code - if it was hard to write, it should be hard to understand.

  3. #3
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: LOAD DATA LOCAL INFILE help...

    Quote Originally Posted by marshian View Post
    Try to use mysql_error() to know more about the error mysql encounters.
    Good advice and it did help a lot!

    I have added this into the code and narrowed the error to these lines..

    OPTIONALLY ENCLOSED BY '\"'
    LINES TERMINATED BY '\n'

    which I have now removed!

    Now I'm getting this error..

    File 'C:\Temp\testdata.csv' not found (Errcode: 2)

    I've tried to reverse the \ to / but no change. Bizarre!

+ Reply to Thread

Similar Threads

  1. Server Time-Zone To Local Time-Zone
    By rockee in forum Tutorials
    Replies: 4
    Last Post: 06-02-2008, 09:58 AM
  2. 9000+ websites down due to explosion at H1 data center
    By jonathanyaniv in forum Off Topic
    Replies: 15
    Last Post: 06-01-2008, 08:19 PM
  3. HTML help...
    By anuj_web in forum Programming Help
    Replies: 5
    Last Post: 05-08-2008, 11:22 AM
  4. Sign In, says cannot load data.
    By brendan93 in forum Free Hosting
    Replies: 1
    Last Post: 09-09-2007, 09:32 AM
  5. vBulletin - Optimization !!!!!
    By bin_asc in forum Scripts & 3rd Party Apps
    Replies: 7
    Last Post: 08-05-2005, 04:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers