语法错误,PHP 中意外的 T_CONSTANT_ENCAPSED_STRING

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2719350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:28:43  来源:igfitidea点击:

Syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in PHP

phpmysqlsqlinto-outfile

提问by pmms

mysql_connect("localhost","root","");
mysql_select_db("hitnrunf_db");

$result=mysql_query("select * from jos_users INTO OUTFILE 'users.csv' FIELDS ESCAPED BY '""' TERMINATED BY ',' ENCLOSED BY '"'
 LINES TERMINATED BY '\n' ");

header("Content-type:  text/plain");
header("Content-Disposition: attachment; filename=your_desired_name.xls");
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";

in the above code in query string i.e string in side mysql_quey

在上面的代码中查询字符串即mysql_quey侧的字符串

we are getting following error

我们收到以下错误

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\wamp\www\samples\mysql_excel\exel_outfile.php on line 8

in query string '\n' charter is not identifying as string thats why above error getting

在查询字符串 '\n' 中,章程未识别为字符串,这就是为什么出现上述错误

回答by codaddict

You need to escape the double quote as: \"instead of ""

您需要将双引号转义为:\"而不是""

$result=mysql_query("select * from jos_users INTO OUTFILE 'users.csv' FIELDS ESCAPED BY '\"' TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n' ");

An un-escaped "will prematurely terminate the string.

未转义"将过早终止字符串。

Example:

例子:

This is incorrect: "A " is a double quote"
This is correct: "A \" is a double quote"

这是不正确的:"A " is a double quote"
这是正确的:"A \" is a double quote"