Home >Database >Mysql Tutorial >How do you access OUT parameters from MySQL stored procedures in PHP?
Accessing Out Values in PHP MySql Stored Procedures
MySQL documentation offers limited guidance on accessing out parameters in stored procedures. Here's how to retrieve an out parameter value using PHP:
Answer:
As mentioned in a previous discussion on the MySQL forums:
For PHP's mysqli API, using a stored procedure with an IN parameter (i) and OUT parameter (j), such as "myproc( IN i int, OUT j int)":
<code class="php">$mysqli = new mysqli("HOST", "USR", "PWD", "DBNAME"); $ivalue = 1; $res = $mysqli->multi_query("CALL myproc($ivalue, @x);SELECT @x"); if ($res) { $results = 0; do { if ($result = $mysqli->store_result()) { echo "<b>Result #$results</b>:<br/>"; while ($row = $result->fetch_row()) { foreach ($row as $cell) echo $cell, " "; } $result->close(); if ($mysqli->more_results()) echo "<br/>"; } } while ($mysqli->next_result()); } $mysqli->close();</code>
The above is the detailed content of How do you access OUT parameters from MySQL stored procedures in PHP?. For more information, please follow other related articles on the PHP Chinese website!