Home >Database >Mysql Tutorial >How do you access OUT parameters from MySQL stored procedures in PHP?

How do you access OUT parameters from MySQL stored procedures in PHP?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-02 08:26:02747browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn