使用MySQL 預存程序存取PHP 中的OUT 參數
使用MySQL 儲存程序存取PHP 中的OUT 參數使用PHP 在MySQL 中處理預存程序時,取得由於文件有限,「 OUT”參數可能是一個挑戰。然而,這個過程可以透過利用 mysqli PHP API 來實現。
使用mysqli$mysqli = new mysqli( "HOST", "USR", "PWD", "DBNAME" );
$ivalue=1;
// Execute the stored procedure and store the result.
$res = $mysqli->multi_query( "CALL myproc($ivalue,@x);SELECT @x" );
if( $res ) {
$results = 0;
// Iterate through the results.
do {
if ($result = $mysqli->store_result()) {
// Display the result header.
printf( "<b>Result #%u</b>:<br/>", $results );
// Fetch and display the OUT parameter value.
while( $row = $result->fetch_row() ) {
foreach( $row as $cell ) {
echo $cell, " ";
}
}
$result->close();
if( $mysqli->more_results() ) echo "<br/>";
}
} while( $mysqli->next_result() );
}
// Close the mysqli connection.
$mysqli->close();
$mysqli = new mysqli( "HOST", "USR", "PWD", "DBNAME" );
$i值=1;
// 執行預存程序並儲存結果。
$res = $mysqli->multi_query( "CALL myproc($ivalue,@x);SELECT @x" );
如果($res){
$結果= 0;
// 迭代結果。
做 {
if ($result = $mysqli->store_result()) {
// 顯示結果標題。
printf( "結果 #%u:
", $results );
// 取得並顯示 OUT 參數值。
while( $row = $result->fetch_row() ) {
foreach( $row 作為 $cell ) {
echo $cell, " ";
}
}
$結果->關閉();
if( $mysqli->more_results() ) echo "
";
}
while( $mysqli->next_result() );
}
// 關閉 mysqli 連線。
$mysqli->close();
在此範例中,「j」參數的值儲存在「result」物件中,並使用 fetch_row() 方法取得。這允許我們存取並顯示預存程序中 OUT 參數的值。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3