简体   繁体   English

PHP / MYSQL-通过php变量与mysql查询相关的语法错误

[英]PHP/MYSQL - Syntax error relating to a mysql query through as php variable

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. 我知道这与LOAD DATA ...行中的'字符的转义有关。 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! 谢谢!

Missing an escape character, this is the correct string: 缺少转义字符,这是正确的字符串:

$uploadQuery = "
LOAD DATA LOCAL INFILE '".$docRoot."/../../includes/dbUploads/".$fileToUpload."' 
INTO TABLE `promotions` 
FIELDS TERMINATED BY ',' 
ENCLOSED BY '\"' 
ESCAPED BY '\\' 
LINES TERMINATED BY '\\r\\n'  
";

Note the extra \\ on the 5th line. 请注意第5行上的\\ 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. 它将"作为字符串终止符。另外一个问题(不会引起语法错误)在第7行,您需要转义反斜杠。

PS the markup analyzer even picked it up :P PS标记分析器甚至把它捡起来:P

Edit: you probably also need to change line 7 to ESCAPED BY '\\\\\\\\' since this reduces to ESCAPED BY '\\\\' after PHP parses it. 编辑:您可能还需要将第7行更改为ESCAPED BY '\\\\\\\\'因为在PHP解析后,这会减少为ESCAPED BY '\\\\'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM