PHP/MYSQL - 通过 as php 变量进行 mysql 查询相关的语法错误
我在以下变量中遇到语法错误问题:
$uploadQuery = "
LOAD DATA LOCAL INFILE '".$docRoot."/../../includes/dbUploads/".$fileToUpload."'
INTO TABLE `promotions`
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\r\n'
";
我知道它与 LOAD DATA... 行中 '
字符的转义有关。但当谈到问题到底是什么,或者如何以正确的方式重写这个查询时,我感到很困惑。
所以,我的问题是:
我如何以正确的方式重写所述变量,以免出现与之相关的语法错误。
如果有人对此有任何建议或意见,我们将不胜感激。
谢谢你!
I am having a problem with syntax errors in the following variable:
$uploadQuery = "
LOAD DATA LOCAL INFILE '".$docRoot."/../../includes/dbUploads/".$fileToUpload."'
INTO TABLE `promotions`
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\r\n'
";
I know that it has something do do with the escaping of the '
characters in the LOAD DATA... line. But I am stumped when it comes to what exactly the problem is, or how to reword this query in the correct manner.
So, My question is this:
How do i reword the stated variable in the correct manner, as to have no syntax errors relating to it.
If anyone has any suggestions or input with this, it would be greatly appreciated.
Thank You!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
缺少转义字符,这是正确的字符串:
请注意第 5 行额外的
\
。它将"
视为字符串终止符。另一个问题(不会导致语法错误)位于第 7 行,您需要转义反斜杠。PS标记分析器甚至选择了它up :P
编辑:您可能还需要将第 7 行更改为
ESCAPED BY '\\\\'
因为在 PHP 解析它之后这会减少为ESCAPED BY '\\'
。Missing an escape character, this is the correct string:
Note the extra
\
on the 5th line. It was treating the"
as a string terminator. Also another problem (that doesn't cause a syntax error) is on the 7th line, you need to escape the backslashes.P.S. the markup analyzer even picked it up :P
Edit: you probably also need to change line 7 to
ESCAPED BY '\\\\'
since this reduces toESCAPED BY '\\'
after PHP parses it.