使用 MySQLi 從預存程序中擷取多個結果集
您的預存程序「multiples」會產生多個結果集。若要前進到後續結果集並從中擷取數據,請使用MySQLi 擴充功能執行下列步驟:
PHP 流程樣式:
<code class="php">// Prepare the statement $stmt = mysqli_prepare($db, 'CALL multiples(?, ?)'); // Bind parameters mysqli_stmt_bind_param($stmt, 'ii', $param1, $param2); // Execute the statement mysqli_stmt_execute($stmt); // Fetch the first result set $result1 = mysqli_stmt_get_result($stmt); while ($row1 = $result1->fetch_assoc()) { echo "Result 1: " . $row1['id'] . "\n"; } // Advance to the second result set mysqli_stmt_next_result($stmt); $result2 = mysqli_stmt_get_result($stmt); // Fetch and print the second result set while ($row2 = $result2->fetch_assoc()) { echo "Result 2: " . $row2['id'] . "\n"; } // Close the statement mysqli_stmt_close($stmt);</code>
PHP 物件-定向樣式:
<code class="php">// Create a prepared statement object $stmt = $db->prepare('CALL multiples(?, ?)'); // Bind parameters $stmt->bind_param('ii', $param1, $param2); // Execute the statement $stmt->execute(); // Fetch the first result set $result1 = $stmt->get_result(); while ($row1 = $result1->fetch_assoc()) { echo "Result 1: " . $row1['id'] . "\n"; } // Advance to the second result set $stmt->next_result(); // Store and print results from the second result set $result2 = $stmt->get_result(); while ($row2 = $result2->fetch_assoc()) { echo "Result 2: " . $row2['id'] . "\n"; } // Close the statement $stmt->close();</code>
附加說明:
- 前進到下一個結果集後,必須先取得並處理它,然後才能取得繼續到下一個。
- 如果您的預存程序產生作為空字串傳回的整數,請檢查資料庫表中的列類型。
- 考慮在 MySQLi 中使用物件導向的樣式以實現更乾淨以及更多封裝的程式碼結構。
以上是如何在 PHP 中使用 MySQLi 從預存程序中檢索多個結果集?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

使用依賴注入(DI)的原因是它促進了代碼的松耦合、可測試性和可維護性。 1)使用構造函數注入依賴,2)避免使用服務定位器,3)利用依賴注入容器管理依賴,4)通過注入依賴提高測試性,5)避免過度注入依賴,6)考慮DI對性能的影響。

phpperformancetuningiscialbecapeitenhancesspeedandeffice,whatevitalforwebapplications.1)cachingwithapcureduccureducesdatabaseloadprovesrovessetimes.2)優化

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

TOOPTIMIZEPHPAPPLICITIONSFORPERSTORANCE,USECACHING,數據庫imization,opcodecaching和SererverConfiguration.1)InlumentCachingWithApcutCutoredSatfetchTimes.2)優化的atabasesbasesebasesebasesbasesbasesbaysbysbyIndexing,BeallancingAndWriteExing

依賴性注射inphpisadesignpatternthatenhancesFlexibility,可檢驗性和ManiaginabilybyByByByByByExternalDependencEctenceScoupling.itallowsforloosecoupling,EasiererTestingThroughMocking,andModularDesign,andModularDesign,butquirscarecarefulscarefullsstructoringDovairing voavoidOverOver-Inje

PHP性能優化可以通過以下步驟實現:1)在腳本頂部使用require_once或include_once減少文件加載次數;2)使用預處理語句和批處理減少數據庫查詢次數;3)配置OPcache進行opcode緩存;4)啟用並配置PHP-FPM優化進程管理;5)使用CDN分發靜態資源;6)使用Xdebug或Blackfire進行代碼性能分析;7)選擇高效的數據結構如數組;8)編寫模塊化代碼以優化執行。

opcodecachingsimplovesphperforvesphpermance bycachingCompiledCode,reducingServerLoadAndResponSetimes.1)itstorescompiledphpcodeinmemory,bypassingparsingparsingparsingandcompiling.2)useopcachebachebachebachebachebachebachebysettingparametersinphametersinphp.ini,likeememeryconmorysmorysmeryplement.33)


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

Atom編輯器mac版下載
最受歡迎的的開源編輯器

Dreamweaver CS6
視覺化網頁開發工具

WebStorm Mac版
好用的JavaScript開發工具