从mysql存储过程获取输出值到php?

时间:2019-08-28 16:49:42

标签: php mysql stored-procedures

我如何从存储过程获取输出值到php变量..

示例存储过程:

DROP PROCEDURE `test`; CREATE DEFINER=`mydbinstance`@`%` PROCEDURE `test`(OUT `max` INT(11)) NOT DETERMINISTIC MODIFIES SQL DATA SQL SECURITY DEFINER

BEGIN 
SELECT MAX(slno)+1 INTO @max FROM table1; 
SELECT @max; 
END

php:

$stmt=mysqli_query($conn,"CALL test();");

1 个答案:

答案 0 :(得分:0)

您应该能够以与任何其他查询相同的方式获取存储过程的结果:

$stmt = mysqli_query($conn,"CALL test();");
if ($row = mysqli_fetch_row($stmt)) {
    $value = $row[0];
}