[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 929
  • Last Modified:

read second row of csv file using php

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.
0
redcoder
Asked:
redcoder
  • 3
  • 2
1 Solution
 
steelseth12Commented:
LOAD DATA INFILE 'pathtocvsfile' INTO TABLE tablename IGNORE 2 LINES;

For more info look at http://dev.mysql.com/doc/refman/5.0/en/load-data.html
0
 
redcoderAuthor Commented:
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
0
 
steelseth12Commented:
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 ");
0
 
redcoderAuthor Commented:
great. that really works.

 you are great steelseth12..

:-)

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now