read second row of csv file using php

Posted on 2007-07-23
Last Modified: 2013-12-13
Anyone know how to read a second row of a csv file using PHP?
 I want to import only starting from second row onwards of the csv file into mysql.
Question by:redcoder
    LVL 20

    Expert Comment

    LOAD DATA INFILE 'pathtocvsfile' INTO TABLE tablename IGNORE 2 LINES;

    For more info look at

    Author Comment

    Is it possible to use those command with php? I tried with :

    mysql_query("LOAD DATA INFILE 'vehicledata.csv' INTO TABLE 'vehicledatatemp' FIELDS TERMINATED BY ',' IGNORE 2 LINES ");    

     in php but it doesn't work
    LVL 20

    Accepted Solution

    Remove the signle colons from the table name

    mysql_query("LOAD DATA INFILE 'vehicledata.csv' INTO TABLE vehicledatatemp FIELDS TERMINATED BY ',' IGNORE 2 LINES ");    

    and use a full path to your csv file

    if your csv file is in the same directory are you php file you can do

    mysql_query("LOAD DATA INFILE '".dirname($_SERVER['SCRIPT_FILENAME'])."/vehicledata.csv' INTO TABLE vehicledatatemp FIELDS TERMINATED BY ',' IGNORE 2 LINES ");

    Author Comment

    great. that really works.

     you are great steelseth12..


    LVL 20

    Expert Comment

    Glad i could help.
    Thank you for the points and the grade.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to count occurrences of each item in an array.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now