MySQL Forums
Forum List  »  Stored Procedures

Re: How to concatenate SQL within a stored procedure?
Posted by: Peter Brawley
Date: June 20, 2013 03:35PM

> This sproc is being called by a php script executed in a browser.

That's a problem. The mysql interface lets you call exactly one sproc with one query result before the connection folds up. The mysqli interface is not broken in that way, but it's cumbersome, needing code like this assuming 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();

We all learned in school or books to encapsulate program logic in routines. But moving your routines from PHP to sprocs would have to yield a huge benefit to offset the above disadvantages. For you, what's that advantage?

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: How to concatenate SQL within a stored procedure?
2045
June 20, 2013 03:35PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.