So I changed my script to use the LOAD DATA LOCAL INFILE since it is supposed to me much faster. The problem is I can't get my dates to populate properly.
I have this now. (I've tried 50 different things)
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
echo $target_file;
// Get file for processing
$sql = "
LOAD DATA LOCAL INFILE \"C:/GIT/Production/csv/$target_file\"
INTO TABLE exp_subs
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
(id,site_id,hash,member_id,card_id,coupon_id,plan_id,voucher_id,entry_id,recurring_interval,recurring_interval_count,amount,total_amount,total_cycles,status,renew,trial_starts_at,trial_ends_at,retry_count,retry_date,shipping_name,shipping_address1,shipping_address2,shipping_address3,shipping_city,shipping_state,shipping_zip,shipping_country,notes,test_mode,created_by,updated_by,canceled_by,next_billing_at,last_billed_at,@var1,@var2,@var3,@var4,@var5,@var6)
SET ended_at = STR_TO_DATE(@var1, '%Y-%m-%d %H:%i:%S'),
canceled_at = STR_TO_DATE(@var2, '%Y-%m-%d %H:%i:%S'),
expires_at = STR_TO_DATE(@var3, '%Y-%m-%d %H:%i:%S'),
created_at = STR_TO_DATE(@var4, '%Y-%m-%d %H:%i:%S'),
updated_at = STR_TO_DATE(@var5, '%Y-%m-%d %H:%i:%S'),
deleted_at = STR_TO_DATE(@var6, '%Y-%m-%d %H:%i:%S')
";
mysql_query($sql) or die(mysql_error());
} else {
echo "Sorry, there was an error uploading your file.";
}
This pulls everything in except the dates. The dates are still being brought in as '0000-00-00 00:00:00'. This is the same thing that happens if I use the simpler version like this:
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
echo $target_file;
// Get file for processing
$sql = "
LOAD DATA LOCAL INFILE \"C:/GIT/Production/csv/$target_file\"
INTO TABLE exp_subs
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
";
mysql_query($sql) or die(mysql_error());
} else {
echo "Sorry, there was an error uploading your file.";
}
The CSV file keeps the dates in this format: "4/21/2016 7:00"
How do I convert them from the file uploaded to the way I need them?