Welcome to WebDesignForums.net!
You're currently viewing WDF as a guest. By registering for a free account, you'll be able to participate with other members in our friendly community. Being a member allows you to ask questions and get answers for those troublesome web development tasks!

In addition, as a member you'll be able to post your websites up for review. Using our unique website review system you can gain some amazing feedback from some of the best web developers around. This is a completely free service to all registered members.

Ready to register yet? Registration is 100% free. Click Here To Join Now!

Data Import into MySQL

Discussion in 'Database Systems Help' started by nmaster64, Sep 15, 2007.

  1. Offline

    nmaster64 New Member

    Message Count:
    19
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    NCSU
    I'm working a job for a guy who's got a rather extensive database of business listings that I need to get into an SQL database. What I'm faced with is how to import that huge chunk of data. He and his partner will reformat it however they need to so I can just pretty much click and import it, but I'm trying to figure out a good way to go about this. Basically, is there an easy way for them to arrange the data in something simple like Excel or Access and I just convert that to a .sql and import it?


  2. Offline

    Shadowfiend Code beautifully and honorably

    Message Count:
    4,146
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Atlanta, GA
    Usually if you use a good tool frontend they'll let you import CSV (comma-separated values) data. Sometimes even Excel data. phpMyAdmin supports the former and possibly the latter for MySQL, for example.


  3. Offline

    dmsoft New Member

    Message Count:
    1
    Likes Received:
    0
    Trophy Points:
    0


  4. Offline

    imagn New Member

    Message Count:
    156
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Los Angeles
    If it's any sort of "flat" file why not just read it and insert it via a script. At least this way you can control and/or format the information as you pull it in.

    <?php
    $filename = "filename.csv"; // FILE TO OPEN - CHANGE AS NEEDED
    $fd = fopen($filename, "r");
    $contents = fread($fd, filesize($filename));
    $deliminator = "\n"; // CHARACTER TO SPLIT LINES - CHANGE AS NEEDED
    $splitlines = explode($deliminator, $contents);
    $loopcount = count($splitlines);
    $var = 0;
    for ($i = 0; $i < $loopcount; $i++) {
    // 0 - Column 1 Info
    // 1 - Column 2 Info
    $value = $splitlines[$var];
    $value = explode(",", $value);
    $var++;
    $query = " INSERT INTO tableName
    (
    column_1,
    column_2
    )
    VALUES
    (
    '$value[0]',
    '$value[1]'
    ) ";
    $result = mysql_query($query);
    }
    ?>


  5. Offline

    nmaster64 New Member

    Message Count:
    19
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    NCSU
    I figured it out, it was just a matter of preping everything just right before hand. Excel and/or OpenOffice Spreadsheet work well for this. You have to remove the headers from the spreadsheet before exporting it to a .CSV file. As ShadowFiend said, phpMyAdmin makes it pretty easy to import, you just have to make sure you've already created the table and that the fields match the columns perfectly.


Share This Page