I am at wits end on this. I have researched this to death and cannot seem to resolve. I have the following PHP statement:
$sqlstatement="LOAD DATA LOCAL INFILE '$temp' INTO TABLE contacts FIELDS
TERMINATED BY ','
LINES TERMINATED BY '\r'
IGNORE 1 LINES
(@ignore, @ID, @Name, @Email, @Type, @Hash, @Time)
SET Date_Update=date('Y-m-d')
";
My CSV file includes the following header row: ID, User Name, User Email, Type.
ID User Name User Email Type
12345 Jackson, F fj@me.com Level 1
67890 Stewart, J js@me.com Level 1
43210 Fuller, T tf@me.com Level 2
62295 Lewis, M ml@me.com Level 2
The CSV file also has extra fields which I do not need to import. Was hoping I could select which fields to import. Not sure of the technique.
My MYSQL table has the following fields: Tag (auto-increment), ID, Name, Email, Type, Hash, Date_Update, Time_Update.
I can't seem to figure out how to use the SET feature in this command. I set @ignore to skip the Tag (auto-increment field).
- How do I get the CSV "User Name" field into the MYSQL "Name" field?
- How do I generate today's date for the MYQL "Date_Update" field? I tried SET Date_Update=date('Y-m-d') but it shows up blank.
- How do I generate a Hash from the CSV "ID" field? I tried Hash=Hash('sha384',$pre.@ID.$suf)
I'm at a loss. Any help would be appreciated.