PHP + MySql + Stored Procedures, how do I get access an “out” value?

后端 未结 2 616
我在风中等你
我在风中等你 2020-11-29 07:27

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 valu

相关标签:
2条回答
  • 2020-11-29 08:08

    it looks like it's answered in this post:

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

    With mysqli PHP API:

    Assume 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();
    
    0 讨论(0)
  • 2020-11-29 08:24

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

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

    0 讨论(0)
提交回复
热议问题