Syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in PHP [closed]

风流意气都作罢 提交于 2019-11-27 08:42:48

问题


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

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


回答1:


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"



来源:https://stackoverflow.com/questions/2719350/syntax-error-unexpected-t-constant-encapsed-string-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!