Php mysql statement with set and select
I have a weird problem, when i use the query on phpmyadmin, it works. but when i use using a php script it returns an error.
Warning: m开发者_JS百科ysql_fetch_array() expects parameter 1 to be resource, boolean given in
I tried to troubleshoot and discovered that the problem lies with the set statement.
this is my example code.
$sql = 'set @rank=0; select * from user;';
Please help somebody.
First Run
$sql = set @rank=0;
it will store value of rank
then run:
select * from user;
In sort you need to run both queries separately .
set statement stores values. that can be used by next executing query,
like code below :
$sql ="SET @id:=0";
$Executives=$DB->exec($sql);
$sql = "SELECT @id:=@id+1 as id,pes.* FROM profile_executive_summary as pes where profile_id=".$pid;
$Executives=$DB->fetchAssoc($sql);
See what mysql_error
returns after you run mysql_query('...')
. That might help. In general, mysql_query
only permits one query. You can't separate them by newlines or semicolons. mysqli will do it for you though.
精彩评论