FILE vs和PHPMySQL中MySQL LOAD DATA LOCAL的区别

时间:2017-04-08 19:55:16

标签: php mysql

我有一个声明

LOAD DATA LOCAL INFILE 'location\\march.csv' 
            INTO table waterportal.payments
            FIELDS TERMINATED BY ','
            OPTIONALLY ENCLOSED BY '\"'   
            LINES TERMINATED BY '\r\n'
            IGNORE 7 LINES
            (CustomerReference, AccountStatus, CustomerName, Reference, ProcurementGroup, ContractStatus, @ContractStart, @ContractEnd, ContractDurationMonths, ContractDurationYears, MainBillingAccountFlag, Service, PaymentMethod, TransferOutWater, TransferOutWaste, @DebtOver39Days, @CommissionRate, @ValueBillInMonth, @DateBilled, @PayableCommission,@dummy1,@dummy2,@dummy3)
            SET 
            UploadDate = NOW(),
            ContractStart = STR_TO_DATE(@ContractStart, '%d %b %y'),
            ContractEnd = STR_TO_DATE(@ContractEnd, '%d %b %y'),
            DateBilled = STR_TO_DATE(@DateBilled, '%d %b %y'),
            DebtOver39Days  =  REPLACE(REPLACE(TRIM(@DebtOver39Days), '£', ''), ',',''),
            ValueBillInMonth  = REPLACE(REPLACE(TRIM(@ValueBillInMonth), '£', ''), ',',''),
            PayableCommission  = REPLACE(REPLACE(TRIM(@PayableCommission), '£', ''), ',',''),
            CommissionRate = (TRIM(TRAILING '%' FROM NULLIF(@CommissionRate, ''))/100)
            ;

如果我在WorkBench中运行它可以正常工作。如果我在我的PHP文件中使用相同的语句,则DebtOver39Days,ValueBillInMonth和PayableCommission字段都会失败并输入为0.

我不确定是否有替代方案 DebtOver39Days = REPLACE(REPLACE(TRIM(@ DebtOver39Days),'£',''),',',''),

仍然会从数据开头删除£。

0 个答案:

没有答案