Jump to content

Recommended Posts

I have this query: "LOAD DATA LOCL INFILE '$txtfile' INTO TABLE $table FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';

 

when it loads the file into the database, it looks like this:

userid |    XY   | gondola_no |  date  | time   | processed  ÿþ1  | x123y132|    h123    |20140212| 082219 |       2  | x123y132|    h123    |20140212| 082219 |          |         |            |        |        |    N

If I copy the same data from the csv file and paste it into another csv file  and run it everything is perfect.

 

LOAD DATA LOCL INFILE '$txtfile' INTO TABLE $table CHARACTER SET UTF8 FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';

 

caused an error.

 

What am I doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/286137-load-data-local-file/
Share on other sites

it is likely that your file has been saved with the BOM (byte order mark) characters. use your programming editor to save it without the BOM. if the file itself doesn't contain any utf-8 encoded characters, just save it as an ansi/ascii encoded file.

 

also, that indicates your database column definitions are all probably a character type. your userid should be an integer, your date should be a date data type, and your time should be a time data type (or your date/time should be combined into one datetime data type.)

a) what scanner program?

 

b) in there a chance you opened/closed the file in your programming editor, which could have added the BOM characters to the file?

 

c) you could always read the file using php, remove the leading BOM characters, then save the file.

The program is Kalipso.  The issue is coming from the .csv file downloaded from scanner. When I open it, copy it to notepad and save it as .csv then run it again, it works fine.  So no, it isn't because I opened/closed the file.  I tried to use php to open, read and write the file but it doesn't change anything.  How do you remove the leading BOM characters when you don't really see them?

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.