create procedure(in w varchar(20),out c int)
begin
set @sqlcount=concat('select count(*) into @c from scms_product where  ',w);
prepare stm1 from @sqlcount;
execute stm1;
set c=@c;
set @sql=concat('select * from scms_product where ',w);
prepare stm2 from @sql;
execute stm2;
end上面的存储过程在mysql里运行正常,要求在php里得到out变量c的值,php代码是这样的$rs=$mysqli->query("call p5('cateid=5',@c)");
$res=$mysqli->query("select @c");
$row=$res->fetch_row();
echo $row[0];运行的时候就会出现错误提示,Call to a member function fetch_row() on a non-object  如果我去掉存储过程中的
set @sql=concat('select * from scms_product where ',w);
prepare stm2 from @sql;
execute stm2;
这几行就正常了,请问我的php程序该怎么写?

解决方案 »

  1.   

    create procedure(in w varchar(20),out c int)
    begin
    ..
    这个本身语法上就过不去。建议你能贴出你实际问题的代码以便分析。
      

  2.   

    create procedure SP名字(in w varchar(20),out c int)
    begin
    set @sqlcount=concat('select count(*) into @c from scms_product where  ',w);
    prepare stm1 from @sqlcount;
    execute stm1;
    set c=@c;
    set @sql=concat('select * from scms_product where ',w);
    prepare stm2 from @sql;
    execute stm2;
    end
      

  3.   

    存储过程的名字我忘记打上去了,不是语法上的错误
    我在php里调用@c的时候就会报错