LOAD DATA LOCAL INFILE MySQL/PHP问题

LOAD DATA LOCAL INFILE MySQL/PHP问题

问题描述:

这是我的 MySQL 表结构

Here is my MySQL table structure

id    |   tracking_number   |   order_id

这是CSV文件的结构:(有时缺少order_id,这似乎引起了问题)

Here is the structure of the CSV file: (Sometimes the order_id is missing, and this seems to be causing issues)

"1R2689Y603406","33097"
"1R2689Y603404","33096"
"1R2689Y603414",
"1R2689Y603429","33093"
"1R2689Y603452",

这是我当前无法使用的SQL查询:(文件正在上传,并且正在正确读取,这是查询本身引起的问题)

Here is my current SQL Query which isn't working: (The file is being uploaded, and is being read correctly, it's the query itself which is causing issues)

        $sql = 'LOAD DATA LOCAL INFILE "'.$_FILES['my_file']['tmp_name'].'" 
        INTO TABLE table_tracking
        FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY "\""
        LINES TERMINATED BY "\n" 
        (tracking_number,order_id)';

        mysql_query($sql) or die(myqsl_error());

我的查询出了什么问题?感谢您的帮助!

What is wrong with my query? Thanks for any help!

更改了CSV结构以表示有时会丢失的数据.更改查询以匹配我现在使用的查询

Changed CSV structure to represent missing data that sometimes occurs. Changed query to match the one I am now using

在这里尝试(不是100%确信),但是您是否尝试过添加目标列,例如:

Just trying here (not 100% confident) but did you try adding the destination columns like this:

mysql_query("LOAD DATA LOCAL INFILE '".$_FILES['my_file']['tmp_name']."' 
     INTO TABLE table_tracking FIELDS TERMINATED BY ',' 
     OPTIONALLY ENCLOSED BY '\"' 
     LINES TERMINATED BY '\n'
     (tracking_number,order_id)");

表中有三列,仅提供两个数据.

You have three columns in your table and are only providing two data.