Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Can';看不到解析错误_Php_Sql_Mysqli - Fatal编程技术网

Php Can';看不到解析错误

Php Can';看不到解析错误,php,sql,mysqli,Php,Sql,Mysqli,正在编写我的第一个与SQL交互的PHP脚本。我离得很近,我能闻到它 我试图返回表中的最大日期,并收到以下消息,其中日期应为: 分析错误:语法错误,中出现意外的T_变量 /Applications/XAMPP/xamppfiles/htdocs/tslocal/themes/myname/views/reports/get_vote_date.php 第25行 第25行是$result=mysqli\u查询($dbc,$query)在下面的脚本中 这是剧本,我一直盯着它看,直到我的眼睛流血,但不确

正在编写我的第一个与SQL交互的PHP脚本。我离得很近,我能闻到它

我试图返回表中的最大日期,并收到以下消息,其中日期应为:

分析错误:语法错误,中出现意外的T_变量 /Applications/XAMPP/xamppfiles/htdocs/tslocal/themes/myname/views/reports/get_vote_date.php 第25行

第25行是
$result=mysqli\u查询($dbc,$query)在下面的脚本中

这是剧本,我一直盯着它看,直到我的眼睛流血,但不确定它是“错误的”,因为我是新来的:

<?php # script get_vote_date

// This file contains the db info
// This file establishes a mysql connection, connects to the db and then gets the most recent vote date for a particular page (incident_id).

DEFINE ('DB_USER', 'myname');
DEFINE ('DB_PASSWORD', 'somepass123');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'sitename');


// make the db connection
$dbc = @mysqli_connect('DB_HOST','DB_USER','DB_PASSWORD','DB_NAME')
    OR die ('Could not connect to mysql: ' . mysqli_connect_error());

// Set the encoding
mysqli_set_charset($dbc, 'utf8');

// set the query variable
$query = 'SELECT MAX(rating_date) 
          FROM rating
          WHERE incident_id = $incident_id;'

//connect and run the query
$result = mysqli_query($dbc, $query);

 echo $result;

?>

如果它有任何值,下面是我试图从中提取数据的表的屏幕:

真正的错误-缺少(实际上放错了)分号-在前面的语句中:

$query = 'SELECT MAX(rating_date) 
          FROM rating
          WHERE incident_id = $incident_id;' // <-- TODO: Put the ; outside of the string literal

//connect and run the query
$result = mysqli_query($dbc, $query); 
这当然是一个解析错误。请注意,字符串文字中的分号对PHP没有特殊意义-它不会终止语句(尽管它会产生SQL错误:)


不幸的是,PHP无法在第22行看到您的意图,只能在第25行检测到错误

真正的错误-缺少(实际上放错了)分号-在前面的语句中:

$query = 'SELECT MAX(rating_date) 
          FROM rating
          WHERE incident_id = $incident_id;' // <-- TODO: Put the ; outside of the string literal

//connect and run the query
$result = mysqli_query($dbc, $query); 
这当然是一个解析错误。请注意,字符串文字中的分号对PHP没有特殊意义-它不会终止语句(尽管它会产生SQL错误:)


不幸的是,PHP无法在第22行看到您的意图,只能在第25行检测到错误

前一行末尾缺少分号…初始化
$query
的那一行末尾没有分号-有一个分号终止SQL,但在单引号后也需要一个分号。现在添加了分号“无法连接到mysql:未知mysql服务器主机'DB_host'(1)”。我使用的是localhost,这个常量已设置。我会继续胡闹你不是在传递常数,而是在传递字符串。改为使用此选项:
mysqli\u connect(DB\u主机、DB\u用户、DB\u密码、DB\u名称)
上一行末尾缺少分号…初始化
$query
的行末尾没有分号-有一个分号终止SQL,但在单引号后面也需要一个。现在添加了分号“无法连接到mysql:Unknown mysql server host'DB_host'(1)”。我正在使用localhost,并且设置了此常量。我会继续胡闹。您没有传递常量,而是传递字符串。请改用此命令:
mysqli_connect(DB_主机,DB_用户,DB_密码,DB_名称)
感谢Alex提供的信息谢谢Alex提供的信息