Ok,
Both suggestions were needed to get the files importing. Interestingly in MySQL LOAD DATA INFILE documentation they sow examples using 'IGNORE LINES 1' but it does not work when I use that. The dates however, are still not working correctly.
Rudy, I did as you suggested and isolated the SQL out of PHP, here is what it is now:
Code:
LOAD DATA INFILE "/var/www/ex/libs/page_queries/test_data2.csv"
REPLACE INTO TABLE `__temp_ovgoptjint`
FIELDS TERMINATED BY ';'
IGNORE 1 LINES
(@date, `name`)
SET Date = date_format(STR_TO_DATE(@date, '%b %m, %Y'), '%Y-%m-%-d');
The actual dates that need to be working are formatted as in the CSV file contents below:
Code:
Date;Name
Sep 14, 2009;Bill
Sep 18, 2009;Mike
When I do this it inserts the dates correctly:
Code:
LOAD DATA INFILE "/var/www/ex/libs/page_queries/test_data2.csv"
REPLACE INTO TABLE `__temp_ovgoptjint`
FIELDS TERMINATED BY ';'
IGNORE 1 LINES
(`date`, `name`)
While having this data
Code:
Date;Name
2009-09-14;Bill
2009-09-18;Mike
When using the SET command my date column contains only NULL
Code:
SET Date = date_format(STR_TO_DATE(@date, '%b %m, %Y'), '%Y-%m-%-d');
The way I read the line above is:
- We are setting the Date column with the variable @date as the variable value being operated upon
- The str_to_date() method should use the value of the date variable that is formatted the same way as the CSV files 'abbreviated month + space + day (as digits) + full month (as digits)
- the date_format() method should return a valid date value formatted in 2012-05-30.
I also tried just str_to_date() like:
Code:
SET Date = STR_TO_DATE(@date, %Y-%m-%-d');
This, however would not allow the statement to execute.
Any further ideas on how I might get this date formatted correctly?
Thanks,
Steve
Bookmarks