0

how i can get output value from stored procedure to php variable ..

example Stored procedure :

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();");
FsCode
  • 112
  • 8
  • i feel upcomming bugs with race conditions if you use this value in a other queries.. – Raymond Nijland Aug 28 '19 at 17:06
  • Possible duplicate of [How to call a MySQL stored procedure from within PHP code?](https://stackoverflow.com/questions/3966747/how-to-call-a-mysql-stored-procedure-from-within-php-code) – Dharman Aug 28 '19 at 17:52

1 Answers1

0

You should be able to get the result(s) of a stored procedure the same way you would any other query:

$stmt = mysqli_query($conn,"CALL test();");
if ($row = mysqli_fetch_row($stmt)) {
    $value = $row[0];
}
Alex Barker
  • 4,316
  • 4
  • 28
  • 47