PHP + MySql +存储过程,如何获得“out”值?

时间:2022-04-30 09:58:41

Documentation is severely lacking on anything to do with stored procedures in mysql with PHP. I currently have a stored procedure that I call via PHP, how can I get the value of an out parameter?

在使用PHP使用mysql存储过程方面,文档严重缺乏。我现在有一个通过PHP调用的存储过程,如何获得out参数的值?

2 个解决方案

#1


15  

it looks like it's answered in this post:

这篇文章似乎是这样回答的:

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

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

With mysqli PHP API:

与mysqli PHP API:

Assume sproc myproc( IN i int, OUT j int ):

假设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();

#2


7  

Here's an example of how to do this with mysql, mysqli, and pdo:

这里有一个例子说明如何使用mysql、mysqli和pdo:

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

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

#1


15  

it looks like it's answered in this post:

这篇文章似乎是这样回答的:

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

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

With mysqli PHP API:

与mysqli PHP API:

Assume sproc myproc( IN i int, OUT j int ):

假设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();

#2


7  

Here's an example of how to do this with mysql, mysqli, and pdo:

这里有一个例子说明如何使用mysql、mysqli和pdo:

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

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