久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 php/mysqli 中使用存儲過程檢索多個結果集

Retrieving Multiple Result sets with stored procedure in php/mysqli(在 php/mysqli 中使用存儲過程檢索多個結果集)
本文介紹了在 php/mysqli 中使用存儲過程檢索多個結果集的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個包含多個結果集的存儲過程.我如何前進到 mysqli 中的第二個結果集以獲得這些結果?

I have a stored procedure that has multiple result sets. How do I advance to the 2nd result set in mysqli to get those results?

假設它是一個存儲過程,例如:

Let's say it's a stored proc like:

create procedure multiples( param1 INT, param2 INT )
BEGIN

SELECT * FROM table1 WHERE id = param1;

SELECT * FROM table2 WHERE id = param2;

END $$

PHP 是這樣的:

$stmt = mysqli_prepare($db, 'CALL multiples(?, ?)');

mysqli_stmt_bind_param( $stmt, 'ii', $param1, $param2 );

mysqli_stmt_execute( $stmt );

mysqli_stmt_bind_result( $stmt, $id );

然后這是我無法開始工作的部分.我已經嘗試使用 mysqli_next_result 移動到下一個結果集,但無法讓它工作.我們確實讓它與 mysqli_store_result 和 mysqli_fetch_assoc/array/row 一起工作,但由于某種原因,所有整數都作為空字符串返回.

Then this is the part I can't get to work. I've tried using mysqli_next_result to move to the next result set, but can't get it to work. We did get it to work with mysqli_store_result and mysqli_fetch_assoc/array/row, but for some reason all the ints get returned as blank strings.

有其他人遇到過這個問題并有解決方案嗎?

Any one else come across this and have a solution?

推薦答案

我認為您在這里遺漏了一些東西.這是使用 mysqli 準備好的語句從存儲過程中獲取多個結果的方法:

I think you're missing something here. This is how you can get multiple results from stored procedure using mysqli prepared statements:

$stmt = mysqli_prepare($db, 'CALL multiples(?, ?)');
mysqli_stmt_bind_param($stmt, 'ii', $param1, $param2);
mysqli_stmt_execute($stmt);
// fetch the first result set
$result1 = mysqli_stmt_get_result($stmt);
// you have to read the result set here 
while ($row = $result1->fetch_assoc()) {
    printf("%d
", $row['id']);
}
// now we're at the end of our first result set.

//move to next result set
mysqli_stmt_next_result($stmt);
$result2 = mysqli_stmt_get_result($stmt);
// you have to read the result set here 
while ($row = $result2->fetch_assoc()) {
    printf("%d
", $row['id']);
}
// now we're at the end of our second result set.

// close statement
mysqli_stmt_close($stmt);

使用 PDO 你的代碼看起來像:

Using PDO your code would look like:

$stmt = $db->prepare('CALL multiples(:param1, :param2)');
$stmt->execute(array(':param1' => $param1, ':param2' => $param2));
// read first result set
while ($row = $stmt->fetch()) {
    printf("%d
", $row['id']);
}
$stmt->nextRowset();
// read second result set
while ($row = $stmt->fetch()) {
    printf("%d
", $row['id']);
}

順便說一句:你是故意使用程序風格的嗎?在 mysqli 中使用面向對象的風格會讓你的代碼看起來更有吸引力(我的個人觀點).

By the way: do you use the procedural style deliberately? Using object oriented style with mysqli would make your code look a little bit more appealing (my personal opinion).

這篇關于在 php/mysqli 中使用存儲過程檢索多個結果集的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 国产精品一区在线播放 | 日韩中文字幕在线观看视频 | 欧美在线国产精品 | 国产真实乱全部视频 | 国产精品99久久久久久动医院 | 国产精品久久久av | 爱爱视频在线观看 | 久久久久国产一区二区三区不卡 | 中文字幕不卡在线88 | 日韩视频免费 | 欧美日韩黄色一级片 | 91网站视频在线观看 | 国产精品一区二区无线 | 99精品99久久久久久宅男 | 欧美一级黑人aaaaaaa做受 | 国产传媒在线播放 | 国产夜恋视频在线观看 | 毛片在线看片 | 国产精品一二区 | 91精品国产综合久久婷婷香蕉 | 成人国产精品久久久 | 免费一级片 | 久久久久久久一区 | 亚洲精品国产第一综合99久久 | 秋霞在线一区二区 | 亚洲精品国产偷自在线观看 | 久久久久久久一区 | 九九九视频精品 | 四色永久 | 亚洲色欲色欲www | 天天色av| 日韩中文一区二区三区 | 91久久国产综合久久91精品网站 | 亚洲综合色视频在线观看 | 亚洲国产精品福利 | 最新国产精品 | 麻豆91精品91久久久 | 久久一二| 国产美女视频黄 | 亚洲一区久久 | aaaa网站|