PHP / Mysql加载数据本地Infile
I have tried everything that I can think of, but for some reason I cannot get this to work.
I have a piece of PHP code that loads a locally stored CSV file into a MySQL database. It works perfectly in one script:
$query = 'LOAD DATA LOCAL INFILE \''.$arp_input.'\' INTO TABLE arp_import FIELDS TERMINATED BY \',\' OPTIONALLY ENCLOSED BY \'"\' LINES TERMINATED BY \'
\' (not_used,account_number,check_serial,issue_date,amount,transaction_code,additional_text)';
However, I need to do the same thing (load a CSV) in another script that does essentially the same thing, but generates a different format. Here is the query:
$query = 'LOAD DATA LOCAL INFILE \''.$ap_input.'\' INTO TABLE ap_import FIELDS TERMINATED BY \',\' OPTIONALLY ENCLOSED BY \'"\' LINES TERMINATED BY \'
\' (account_number,check,paiddate,amount)';
But when I run the second script with the above query, I get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'check,paiddate,amount)' at line 1
When I take out the field listing at the end of the second query, it only imports ONE line from the file and that is it, even when I tried the delimiter, , and both .
I have tried everything that I can think of. These two PHP scripts are running on the same server and they are both accessing the same remote MySQL server. What am I missing here?
我已经尝试了所有我能想到的东西,但出于某种原因,我无法让它发挥作用。 p >
我有一段PHP代码,可以将本地存储的CSV文件加载到MySQL数据库中。 它在一个脚本中完美运行: p>
$ query ='LOAD DATA LOCAL INFILE \''。$ arp_input。'\'INTO TABLE arp_import FIELDS TERMINATED BY \',\' 由''
\'(not_used,account_number,check_serial,issue_date,amount,transaction_code,additional_text)'终止的\'“\'LINI封装线;'
code> pre>
但是,我需要在另一个基本相同的脚本中执行相同的操作(加载CSV),但生成不同的格式。以下是查询: p>
$ query ='LOAD DATA LOCAL INFILE \''。$ ap_input。'\'INTO TABLE ap_import FIELDS TERMINATED BY \','''''''''''''''''''''''''''''''' (account_number,check,paiddate,amount)';
code> pre>
但是当我使用上述查询运行第二个脚本时,我收到此错误: p> \ n
您的SQL语法有错误; 检查与您的MySQL服务器版本相对应的手册,以便在第1行的“check,paiddate,amount”附近使用正确的语法
code> pre>
当我取出时 在第二个查询结束时的字段列表中,它只从文件中导入一行,就是它,即使我尝试了
分隔符,
和
。
p>
我尝试过所有我能想到的东西。 这两个PHP脚本在同一台服务器上运行,它们都访问同一个远程MySQL服务器。 我在这里缺少什么? p>
div>
Check is a reserved word according to the MySQL documentation.
check
is a reserved word in MySQL ( http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html ). You should enclose it in back-ticks (`) in your sql sentence: