Quantcast
Channel: PHP - MySQL gets value of out parameter from a stored procedure - Stack Overflow
Viewing all articles
Browse latest Browse all 6

Answer by TerryE for PHP - MySQL gets value of out parameter from a stored procedure

$
0
0

Or even just do a "SELECT @id AS id" then $row->id will work fine. I always rename select columns to keep the name meaningful when necessary :-)

BTW, you can simply concatenate the call and select @... (with a ; statement delimiter) and the RS will be the returned value. Unfortunately this returns a mutli-resultset and you need to flush the full set otherwise the subsequent queries will stall. See following examples:

$db->multi_query( "CALL addNewUser($name,$age,@id);SELECT @id as id" );$db->next_result();            // flush the null RS from the call$rs=$db->store_result();       // get the RS containing the idecho $rs->fetch_object()->id, "\n";$rs->free();

Alternatively add the select into the addNewUser and return a RS instead of out param

$rs = $db->query( "CALL addNewUser($name,$age)" );echo $rs->fetch_object()->id, "\n";$rs->close();$db->next_result();            // flush the null RS from the call

The first returns a multiquery (NULL, RS) set and the second a (RS, NULL) set, hence you can use a simple query() call which embeds the first fetch_object(), but you still need to flush the RS stack.


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>