首页  >  文章  >  后端开发  >  在PHP下 给MYSQL变量报错

在PHP下 给MYSQL变量报错

WBOY
WBOY原创
2016-06-13 10:32:58754浏览

在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