Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
Import csv file into MySQL
Results 1 to 3 of 3

Thread: Import csv file into MySQL

  1. #1
    Mentor cga's Avatar
    Join Date
    May 2001
    Posts
    1,433

    Import csv file into MySQL

    I have a large file with almost 900 contacts for a client. The client submitted this file as an Excel spreadsheet. I have converted it to a csv. I need to get this data into a MySQL table. Each line of the csv file matches the columns in my table (name, company, email, state, Status, ID). ID is set to auto-increment and status (subscribed=1) is set to default 1.

    I tried to use the import feature in phpmyadmin, but had no luck. I am thinking of something like the following PHP script:

    <?
    $fcontents = file ('LIST.csv');

    for($i=0; $i<sizeof($fcontents); $i++) {
    $line = trim($fcontents[$i]);
    $arr = explode(",", $line);
    $sql = "insert into TABLENAME values ('".
    implode("','", $arr) ."')";
    mysql_query($sql);
    echo $sql ."<br>\n";
    if(mysql_error()) {
    echo mysql_error() ."<br>\n";
    }
    }
    ?>


    Any thoughts or better ideas? I am open to sugestions.

    Thanks!
    TANSTAAFL

  2. #2
    My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive.

  3. #3
    Mentor cga's Avatar
    Join Date
    May 2001
    Posts
    1,433
    Quote Originally Posted by trickster
    Ah, much easier. Thanks man.
    TANSTAAFL

Similar Threads

  1. Import Word Document into Publisher
    By regix in forum Windows - General Topics
    Replies: 5
    Last Post: 01-27-2005, 01:56 AM
  2. How to Import Microsoft Access Data
    By regix in forum Windows - General Topics
    Replies: 0
    Last Post: 01-01-2005, 03:13 AM
  3. Import MS Outlook
    By GhostDawg in forum Linux - Software, Applications & Programming
    Replies: 2
    Last Post: 12-24-2004, 12:08 PM
  4. What to import/export via nfs?
    By ph34r in forum Linux - General Topics
    Replies: 3
    Last Post: 11-17-2002, 04:10 PM
  5. Anyway to import MS-Access 97 .mdf files
    By Schotty in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 08-08-2002, 01:37 PM

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
  •