Accessing Out Parameters in PHP MySql Stored Procedures
When working with stored procedures in MySQL using PHP, accessing the values of out parameters can be a challenge. This article provides a solution based on MySQL's documentation and a forum thread.
Method:
Code Example:
<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()) { printf("<b>Result #%u</b>:<br/>", ++$results); 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>
By using this method, you can effectively access the values of out parameters in stored procedures from your PHP code.
The above is the detailed content of How to Access Out Parameters in MySQL Stored Procedures with PHP?. For more information, please follow other related articles on the PHP Chinese website!