严重缺乏与 mysql 和 PHP 中的存储过程有关的任何文档。我目前有一个通过 PHP 调用的存储过程,如何获取输出参数的值?

有帮助吗?

解决方案

看起来它在这篇文章中得到了回答:

http://forums.mysql.com/read.php?52,198596,198717#msg-198717

使用 mysqli PHP API:

假设 sproc myproc( IN i int, OUT j int ):

$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, "&nbsp;";
      }
      $result->close();
      if( $mysqli->more_results() ) echo "<br/>";
    }
  } while( $mysqli->next_result() );
}
$mysqli->close();

其他提示

以下是如何使用 mysql、mysqli 和 pdo 执行此操作的示例:

http://www.joeyrivera.com/2009/using-mysql-stored-procedures-with-php-mysqlmysqlipdo/

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top