我正在尝试使用 php 脚本将一些 csv 和制表符分隔的 txt 提要导入我的数据库。除了这个之外,它们似乎都可以工作。
我有一个包含数据库连接、禁用键、导入每个提要(通过包含语句)和重新启用键的基本 php 脚本,然后再导出最终结果。
导致我出现问题的提要是这个,或者我应该说 sql 语句。
$sql = "
LOAD DATA LOCAL INFILE '../feeds/feed6.txt'
INTO TABLE supplierimport
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\\r\n'
IGNORE 1 LINES
(@col1,@col2,@col3,@col4,@col5,@col6,@col7,@col8,@col9,@col10,@col11,@col12,@col13,@col14,@col15,@col16)
SET
DistributorID = 546, MPN=@col1, Brand=@col6, DistributorSKU=@col1, `Condition`=@col15, ProductName=@col2, Cost= replace(@col4, ',', ''), Stock=@col5, EAN=@col12, ImageURL=@col11, ETA=@col7";
database_queryModify($sql,$result);
print "Imported...";
所以,关于这个有两个问题:
使用这个说法是否正确;
Cost= replace(@col4, ',', ''),
我使用这个语句的原因是因为我将每个供应商的成本导入到cost
我的数据库中的列中,但是这个特定的供应商使用千位分隔符,即1000.53
在提要中显示为1,000.53
,因此没有正确导入我的数据库,所以我找到了替换功能,但想验证我在这种情况下是否正确使用它?文件中正好有一半的行被导入到我的数据库中。我发现了这个问题;如您所见,mysql 使用设置字段加载数据本地 infile 语法问题我已经放了 \r\n,但它仍然没有全部导入。
任何人都可以帮忙。
谢谢
编辑:仅以逗号分隔的文本文件中的三行为例。这是从文件中粘贴的,因此我没有在每行之间添加额外的行。此外,在第 3 行,您会看到价格为“1,117.00”,以显示千位分隔符的工作方式:
"Item No.","Description","Description 2","Customers Price","Home stock","Brand Name","Expected date for delivery","Item Group No.","Item Group Name","Item Product Link (Web)","Item Picture Link (Web)","EAN/UPC","Weight","UNSPSC code","Product type code","Warranty"
"/5PL0006","Drum Unit","DK-23","126.00","32","Kyocera","03/11/2013","800002","Drums","http://uk.product.com/product.aspx?id=%2f5PL0006","http://s.pic.eu/products/2_PICTURE-TAKEN.JPG","5711045360824","0.30","44103109","","3M"
"/DK24","DK-24 Drum Unit FS-3750","","1,117.00","8","Dell","07/11/2013","800002","Drums","http://uk.product.com/product.aspx?id=%2fDK24","http://s.pic.eu/products/2_PICTURE-TAKEN.JPG","5711045360718","0.20","44103109","","3M"