PHP 读取 php 文件输出并将其用作字符串

PHP read php file output and use it as a string

目前我使用一个文件动态生成一个 sql 字符串,该字符串取决于在 URL

中传递的值
$file = file_get_contents('http://xxx.xxx.xxx.xxx/for.php?passenger='.$user_id.'&seat='.$nos.'&seatstatus=BP&coach='.$noc.'&date='.$date.'');
$file_result = $db->query($file);
if($file_result->num_rows>0){
//Do Somthing
}

然而,当我使用这种方法时,输出什么都没有,但是当我

echo $file;

显示正确

如果我通过了http://xxx.xxx.xxx.xxx/for2.php?passenger=32&seat=4&seatstatus=BP&coach=1&date=2015-04-30

那么产生的SQL就是

"SELECT * FROM `Events` WHERE `Date` = '2015-04-30' and `User_1_1` = '32' and `Status_1_1` = 'BP' or `Date` = '2015-04-30' and `User_1_2` = '32' and `Status_1_2` = 'BP' or `Date` = '2015-04-30' and `User_1_3` = '32' and `Status_1_3` = 'BP' or `Date` = '2015-04-30' and `User_1_4` = '32' and `Status_1_4` = 'BP' or `Lookup` = '1'"

所以我不太确定我做错了什么

您需要删除 SQL 两边的双引号 (")。这些不应该是您发送给 MySQL 的查询的一部分,因为这样它是无效的 SQL.