Jump to content

.CVS Import Problem


dragonusthei

Recommended Posts

Im importing the following:

 

"33996344","33996351","GB","GBR","UNITED KINGDOM"

"50331648","69956103","US","USA","UNITED STATES"

"69956104","69956111","BM","BMU","BERMUDA"

"69956112","83886079","US","USA","UNITED STATES"

"94585424","94585439","SE","SWE","SWEDEN"

 

The Current PHP Reads:

 

mysql_query("LOAD DATA LOCAL INFILE 'ip-to-country.csv' 
INTO TABLE ipcountry FIELDS TERMINATED BY ',' ENCLOSED BY '\"'");

 

However this is going wrong after the end of the line because theres no , how can i get round this?

Link to comment
Share on other sites

$query = "LOAD DATA LOCAL INFILE 'ip-to-country.csv' INTO TABLE ipcountry FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n'";

 

the lines terminated by looks for the Return (\r\n) on the line

 

from the manual:

Note that if you created the file on Windows with an editor that uses \r\n as a line terminator, you should use:

mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet

    -> LINES TERMINATED BY '\r\n';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.