Api文档内容
class Demo extends Api
{
//存储过程的使用
public function a1()//执行语句
{
Db::query('call goodmorning()');
}
public function b1()//带返回参数的存储过程
{
$re = Db::query('call b1(2)');//直接输入参数方式
$re = Db::query('call b1(?)',[2]);//参数绑定方式
$re = Db::query('call b1(:value)',['ivalue'=>2]);//绑定方式
return json($re[0][0]["total"]);
}
public function p1()//带out参数的存储过程,
{
Db::query('call c1(100,@total)');
$total = Db::query('select @total');
return json($total[0]["@total"]);
}
}
对应存储过程
CREATE PROCEDURE `a1`()
begin
update a set b=0 ;
end;
CREATE PROCEDURE `b1`(in n int)
begin
declare num int default 0;
declare total int default 0;
while num < n do
set num:=num+1;
set total:=total+num;
end while;
select total;//返回值
end;
CREATE PROCEDURE `c1`(in n int,out total int)
begin
declare num int default 0;
set total:=0;
while num < n do
set num:=num+1;
set total:=total+num;
end while;
end;
对应api调用地址
http://127.0.0.1:8079/api/demo/byetest0