Home  >  Article  >  Backend Development  >  在PHP下 给MYSQL变量报错

在PHP下 给MYSQL变量报错

WBOY
WBOYOriginal
2016-06-13 13:20:51915browse

在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不能一次执行多条语句。分开执行。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn