PHP + MySql + 存储过程,如何访问“out”值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48126/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP + MySql + Stored Procedures, how do I get access an "out" value?
提问by mmattax
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 调用的存储过程,如何获取输出参数的值?
回答by John Boker
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#msg-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, " ";
}
$result->close();
if( $mysqli->more_results() ) echo "<br/>";
}
} while( $mysqli->next_result() );
}
$mysqli->close();
回答by mmattax
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/

