I am trying to import huge csv files without having to split them up and use phpmyadmin.
Here is a sample of my csv format (some fields have "" some dont) I have looked at all other stack overflow answers but none seem to have my situation where some fields have speech marks enclosing and some dont.
Here is a sample of my csv with the first line as the column names:
aw_product_id,merchant_product_id,merchant_category,aw_deep_link,merchant_image_url,search_price,description,product_name,merchant_deep_link,aw_image_url,merchant_name,merchant_id,category_name,category_id,delivery_cost,currency,store_price,display_price,data_feed_id,web_offer,brand_name
3156121231,462496,/cycle/clothing/ladies/gloves,http://www.awin1.com/pclick.php?p=3156121231&a=117981&m=2485,http://products.activinstinct.com/y2014/m09/462496/14723969-n.jpg,33.49,"A close fitting fully waterproof glove with ProGel palm padding for better cushioning on the handlebars.Features:*Waterproof, windproof, breathable construction*ProGel palm padding*Cuff adjuster for precise fitting*Critically positioned reflective trims","ALTURA ProGel Waterproof Ladies Gloves",http://www.activinstinct.com/cycle/clothing/ladies/gloves/altura-progel-waterproof-ladies-gloves/,http://images.productserve.com/preview/5/2485/31/12/3156121231.jpg,ActivInstinct,2485,"Women's Accessories",149,3.95,GBP,,GBP33.49,2485,0,Altura
This is my php so far:
$pdo = new PDO($dsn, $user, $password, array(PDO::MYSQL_ATTR_LOCAL_INFILE=>1));
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec("LOAD DATA LOCAL INFILE 'example.csv'
INTO TABLE products
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\'
LINES TERMINATED BY '
'
IGNORE 1 LINES
(aw_product_id,merchant_product_id,merchant_category,aw_deep_link,merchant_image_url,search_price,description,product_name,merchant_deep_link,aw_image_url,merchant_name,merchant_id,category_name,category_id,delivery_cost,currency,store_price,display_price,data_feed_id,web_offer,brand_name);");
It errors unless I remove the enclosed by ". With that removed it submits the large csv but the formatting is wrong and fields are put into the wrong columns.
Any help would be greatly appreciated i'm sure its something small and stupid but this has been bugging me for days!
Thanks in advance!
I managed to get the csv file importing using the following library for laravel https://github.com/goodby/csv