Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Location
    UK
    Posts
    30

    Unanswered: PHP / MySQL Load Data In File

    Hope someone can help.

    I have been working on a web-app that needs to do very large imports from text or csv. The file is uploaded via form post or via ftp depending on size to a client specific location on the server. The page then uses


    mysql_query("LOAD DATA INFILE '$filename' INTO TABLE `csv` FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';",$con)

    where $filename is the path to the file.

    On the old Windows box this worked fine. Howerver, on the new Fedora Core 4 box, this now falls over with the error message that the file must be either in the database directory or globally readable.

    I can't write the file to the database dir as I/m not sure of the security issues in doing this on linux, and using CHMOD on the file via PHP doesnt seem to help.

    I can't use a line by line parse as the file is too large and the code will time out.

    Does anyone know how to get Load Data INFILE to work correctly on Linux.

    Thanks in advance.

  2. #2
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    Add the LOCAL keyword - LOAD DATA LOCAL INFILE

    Also, you might need to make the $filename path a fully specified absolute path on your server rather than a relative one (doing this might allow the non-LOCAL version to work, which would result in the fastest possible loading.)

  3. #3
    Join Date
    Mar 2004
    Location
    UK
    Posts
    30
    brilliant. so simple. works perfectly. thank you. very much appreciated

  4. #4
    Join Date
    Feb 2009
    Posts
    1

    Problem in date fields

    I am trying to upload data from csv to table, while I have date fields in csv, those are converted into mm/dd/yyyy format in csv. And since the format is invalid to mysql, they are uploaded as empty (0000-00-00).

    Can anyone suggest me to solve this ?

    Thanks in advance.
    -Sakthikumar

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    coerce the date to be the iso date format yyyy mm dd
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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