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

时间:2015-04-12 12:01:06

标签: php sql file-get-contents

目前我使用一个文件动态生成一个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'"

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

1 个答案:

答案 0 :(得分:3)

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

相关问题