SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Loading CSV File into MySQL with PHP

    Hi, I’m in desperate need of help loading a csv file into a mysql database. I tried to use the easiest method of ‘LOAD DATA INFILE’ but it wouldn’t work and after talking to my hosts tech support I was told as of mysql 4.0 the LOAD command in the mysql command line is not permitted and that they prefer you use mysqlimport. I did my research and for the life of me I couldn’t get mysqlimport to work in a php script.

    Can someone please offer assistance? Thank you very much in advance.

  2. #2
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    vta,ca,usa
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1) You don't use mysqlimport from PHP. (you could, I suppose, but it would be too much trouble) Doesn't your host offer a shell? Obviously if they've locked you out from using the LOAD DATA INFILE command and offered `mysqlimport` surely they allow you to login and use it...

    2) You may very well be able to use PHPMyAdmin in some capacity to import the file...do you have access to that?

    3) Depending on the structure of the file, you might be able to simply turn it into one big 'INSERT INTO' type command like so:
    Code:
    data, 1, 500, name, email
    moredata, 4, 3000, name, email
    becomes
    Code:
    INSERT INTO table VALUES
    (data, 1, 500, name, email),
    (moredata, 4, 3000, name, email)
    ;
    With a good text editor you can use search and replace to insert all those opening and closing parenthesis...that technique saved me alot of trouble more than once...

    And finally....move to MySQL forum.

  3. #3
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm writing this script for a client who doesn't know the first thing php or mysql so going shell isn't an option.

    I did try PHPMyAdmin but they use the LOAD command.

  4. #4
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still looking for possible answers. Anyone else with help to offer?

  5. #5
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I guess I'd do it like bdl said. Generate create and insert queries.


Bookmarks

Posting Permissions

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