在PHP代码中运行时,SET和SELECT查询不执行

时间:2013-03-23 20:06:20

标签: php mysql

我有这个PHP代码 - :

$q = "SET @session = '1', @buddys = '12,7,10', @rejects = 'post_0'; SELECT f.* FROM feed as f"; $r = mysqli_num_rows($q);.


这会导致此错误 - :You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT f.* FROM feed as f' at line 3

但令人惊讶的是,当在phpmyadmin中运行相同的mysql查询时,它会根据需要运行。

是什么事?谢谢你的帮助...

1 个答案:

答案 0 :(得分:0)

在选择

之前,您的问题是分号;

尝试用逗号,

替换它 像那样

 $q = "SET @session = '1', @buddys = '12,7,10', @rejects = 'post_0' , SELECT f.* FROM feed as f";
  $r = mysqli_num_rows($q);

或者你也应该像你那样分开你的查询

   $q = "SET @session = '1', @buddys = '12,7,10', @rejects = 'post_0' ";
   $q .= "SELECT f.* FROM feed as f";