我试图导入巨大的csv文件,而不必拆分它们并使用phpmyadmin。
这是我的csv格式的示例(某些字段有“”一些不)我已经查看了所有其他堆栈溢出答案但似乎没有我的情况,其中一些字段有语音标记封闭,有些不。“/ p >
以下是我的csv样本,第一行作为列名:
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
到目前为止这是我的php:
$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 '\r\n'
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);");
它会出错,除非我删除了所附的“。删除后,它会提交大型csv,但格式错误,字段放入错误的列。
任何帮助都会非常感激,我确信它的东西很小而且很愚蠢,但这已经困扰了我好几天了!
提前致谢!