mysql中如何获取没有输入参数的存储过程的返回值
答案:2 悬赏:70 手机版
解决时间 2021-02-10 05:16
- 提问者网友:世勋超人
- 2021-02-10 00:27
mysql中如何获取没有输入参数的存储过程的返回值
最佳答案
- 五星知识达人网友:孤独的牧羊人
- 2021-02-10 00:34
p_cloumns varchar(500),p_tables varchar(100),p_where varchar(4000),p_order varchar(100),p_pageindex int,p_pagesize int,out p_recordcount int,out p_pagecount int
$:begin
declare v_sqlcounts varchar(4000);
declare v_sqlselect varchar(4000);
#拼接查询总记录的SQL语句
set v_sqlcounts = concat('select count(*) into @recordcount from ',p_tables,p_where);
#select v_sqlcounts;leave $;
set @sqlcounts = v_sqlcounts;
prepare stmt from @sqlcounts;
execute stmt;
deallocate prepare stmt;
#获取动态SQL语句返回值
set p_recordcount = @recordcount;
#根据总记录跳数计算出总页数
set p_pagecount = ceiling((p_recordcount+0.0)/p_pagesize);
if p_pageindex <1 then
set p_pageindex = 1;
elseif p_pageindex > p_pagecount and p_pagecount <> 0 then
set p_pageindex = p_pagecount;
end if;
#拼接分页查询记录的动态SQL语句
set v_sqlselect = concat('select ',p_cloumns,' from ',p_tables,p_where,if(p_order is not null,p_order,''),' limit ',(p_pageindex-1)*p_pagesize,' , ',p_pagesize);
#select v_sqlselect;leave $;
set @sqlselect = v_sqlselect;
prepare stmtselect from @sqlselect;
execute stmtselect;
deallocate prepare stmtselect;
end $
$:begin
declare v_sqlcounts varchar(4000);
declare v_sqlselect varchar(4000);
#拼接查询总记录的SQL语句
set v_sqlcounts = concat('select count(*) into @recordcount from ',p_tables,p_where);
#select v_sqlcounts;leave $;
set @sqlcounts = v_sqlcounts;
prepare stmt from @sqlcounts;
execute stmt;
deallocate prepare stmt;
#获取动态SQL语句返回值
set p_recordcount = @recordcount;
#根据总记录跳数计算出总页数
set p_pagecount = ceiling((p_recordcount+0.0)/p_pagesize);
if p_pageindex <1 then
set p_pageindex = 1;
elseif p_pageindex > p_pagecount and p_pagecount <> 0 then
set p_pageindex = p_pagecount;
end if;
#拼接分页查询记录的动态SQL语句
set v_sqlselect = concat('select ',p_cloumns,' from ',p_tables,p_where,if(p_order is not null,p_order,''),' limit ',(p_pageindex-1)*p_pagesize,' , ',p_pagesize);
#select v_sqlselect;leave $;
set @sqlselect = v_sqlselect;
prepare stmtselect from @sqlselect;
execute stmtselect;
deallocate prepare stmtselect;
end $
全部回答
- 1楼网友:夜风逐马
- 2021-02-10 01:49
用mysqli是可以的
mysqli_query($db,"set names utf8");
$result=$db->query("call gxtj($year,$jd)"); // gxtj是mysql的存储过程名称
while( $row = $result->fetch_array(mysqli_assoc)) //完成从返回结果集中取出一行{while ($key=key($row)){ //依次取得字段名
$value=current($row); //依次取得字段值}}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯