SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Denmark
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Comma-separated files to MySQL

    Hi

    Does anybody know how to tranfer data from a comma-separated file to a MySQL database table.

    Lars, DK

  2. #2
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ach. The MySQL I use has a phpAdmin portal.... I'll have a look at the syntax for you.

    G

  3. #3
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. phpAdmin spat out the following SQL when I tested it quickly:

    Code:
    LOAD DATA LOCAL INFILE '/home/tmp/phpbLAmAj' INTO TABLE test FIELDS TERMINATED BY ', ' ESCAPED BY '\\' LINES TERMINATED BY '\n'
    Sub in what you need really. Obviously, INFILE was created by the server temporarily from the CSV, but I'm assuming that INFILE 'http://www.mysite.com/mycsv.csv' would work just the same. Maybe.

  4. #4
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then again, looking at the options, you'd have to change the LOCAL to something I imagine. Still, now you know the basic command you're after you can check the MySQL documentation.

  5. #5
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Denmark
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Greg! It works fine.

    Lars, DK

  6. #6
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    USA
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.mysql.com/doc/en/LOAD_DATA.html

    How do I pass the file from say a form file field to the SQL statement so I can create a page to upload a file from the desktop and insert into MySQL table?


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
  •