首頁 >後端開發 >php教程 >在PHP下 给MYSQL变量报错

在PHP下 给MYSQL变量报错

WBOY
WBOY原創
2016-06-13 10:32:58763瀏覽

在PHP上 给MYSQL变量报错
$sql = 'SET @rank =0;
  . ' SELECT *FROM (SELECT @rank := @rank +1 AS rank, yb2000_event_phone, yb2000_event_point FROM yb2000_event WHERE yb2000_event_riqi = \'2012-07\' GROUP BY yb2000_event_phone ORDER BY yb2000_event_point DESC )a WHERE a.yb2000_event_phone = \'13333333333\''; 
PHPMYADMIN 里正常能运行 在PHP里报错Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource 删除SET @rank =0;这一段又正常了- - 个位高人指教下

------解决方案--------------------
mysql_query只能执行一条sql语句,你上面是两条sql了
你把他们分开执行试试
------解决方案--------------------
$sql = 'SET @rank =0;';
mysql_query($sql);

 $result=mysql_query(' SELECT * FROM (SELECT @rank := @rank +1 AS rank, yb2000_event_phone, yb2000_event_point FROM yb2000_event WHERE yb2000_event_riqi = \'2012-07\' GROUP BY yb2000_event_phone ORDER BY yb2000_event_point DESC )a WHERE a.yb2000_event_phone = \'13333333333\''); 

mysql_query不能一次执行多条语句。分开执行。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn