
- PHP 教程
- PHP - 首頁
- PHP - 路線圖
- PHP - 簡介
- PHP - 安裝
- PHP - 歷史
- PHP - 特性
- PHP - 語法
- PHP - Hello World
- PHP - 註釋
- PHP - 變數
- PHP - Echo/Print
- PHP - var_dump
- PHP - $ 和 $$ 變數
- PHP - 常量
- PHP - 魔法常量
- PHP - 資料型別
- PHP - 型別轉換
- PHP - 型別混合
- PHP - 字串
- PHP - 布林值
- PHP - 整數
- PHP - 檔案與 I/O
- PHP - 數學函式
- PHP - Heredoc 和 Nowdoc
- PHP - 複合型別
- PHP - 檔案包含
- PHP - 日期和時間
- PHP - 標量型別宣告
- PHP - 返回型別宣告
- PHP 運算子
- PHP - 運算子
- PHP - 算術運算子
- PHP - 比較運算子
- PHP - 邏輯運算子
- PHP - 賦值運算子
- PHP - 字串運算子
- PHP - 陣列運算子
- PHP - 條件運算子
- PHP - 展開運算子
- PHP - 空值合併運算子
- PHP - 比較運算子(太空船運算子)
- PHP 控制語句
- PHP - 決策制定
- PHP - If…Else 語句
- PHP - Switch 語句
- PHP - 迴圈型別
- PHP - For 迴圈
- PHP - Foreach 迴圈
- PHP - While 迴圈
- PHP - Do…While 迴圈
- PHP - Break 語句
- PHP - Continue 語句
- PHP 函式
- PHP - 函式
- PHP - 函式引數
- PHP - 按值傳遞
- PHP - 按引用傳遞
- PHP - 預設引數
- PHP - 命名引數
- PHP - 可變引數
- PHP - 返回值
- PHP - 傳遞函式
- PHP - 遞迴函式
- PHP - 型別提示
- PHP - 變數作用域
- PHP - 嚴格型別
- PHP - 匿名函式
- PHP - 箭頭函式
- PHP - 可變函式
- PHP - 區域性變數
- PHP - 全域性變數
- PHP 超全域性變數
- PHP - 超全域性變數
- PHP - $GLOBALS
- PHP - $_SERVER
- PHP - $_REQUEST
- PHP - $_POST
- PHP - $_GET
- PHP - $_FILES
- PHP - $_ENV
- PHP - $_COOKIE
- PHP - $_SESSION
- PHP 檔案處理
- PHP - 檔案處理
- PHP - 開啟檔案
- PHP - 讀取檔案
- PHP - 寫入檔案
- PHP - 檔案是否存在
- PHP - 下載檔案
- PHP - 複製檔案
- PHP - 追加檔案
- PHP - 刪除檔案
- PHP - 處理 CSV 檔案
- PHP - 檔案許可權
- PHP - 建立目錄
- PHP - 列出檔案
- 面向物件 PHP
- PHP - 面向物件程式設計
- PHP - 類和物件
- PHP - 建構函式和解構函式
- PHP - 訪問修飾符
- PHP - 繼承
- PHP - 類常量
- PHP - 抽象類
- PHP - 介面
- PHP - 特性
- PHP - 靜態方法
- PHP - 靜態屬性
- PHP - 名稱空間
- PHP - 物件迭代
- PHP - 封裝
- PHP - Final 關鍵字
- PHP - 過載
- PHP - 克隆物件
- PHP - 匿名類
- PHP Web 開發
- PHP - Web 概念
- PHP - 表單處理
- PHP - 表單驗證
- PHP - 表單郵件/URL
- PHP - 完整表單
- PHP - 檔案包含
- PHP - GET 和 POST
- PHP - 檔案上傳
- PHP - Cookie
- PHP - Session
- PHP - Session 選項
- PHP - 傳送郵件
- PHP - 過濾輸入
- PHP - Post-Redirect-Get (PRG)
- PHP - 快閃記憶體訊息
- PHP 高階
- PHP - MySQL
- PHP.INI 檔案配置
- PHP - 陣列解構
- PHP - 編碼規範
- PHP - 正則表示式
- PHP - 錯誤處理
- PHP - Try…Catch
- PHP - Bug 除錯
- PHP - 針對 C 開發人員
- PHP - 針對 PERL 開發人員
- PHP - 框架
- PHP - Core PHP 與框架
- PHP - 設計模式
- PHP - 過濾器
- PHP - JSON
- PHP - 異常
- PHP - 特殊型別
- PHP - 雜湊
- PHP - 加密
- PHP - is_null() 函式
- PHP - 系統呼叫
- PHP - HTTP 認證
- PHP - 交換變數
- PHP - Closure::call()
- PHP - 過濾後的 unserialize()
- PHP - IntlChar
- PHP - CSPRNG
- PHP - 預期
- PHP - Use 語句
- PHP - 整數除法
- PHP - 已棄用的功能
- PHP - 已移除的擴充套件和 SAPI
- PHP - PEAR
- PHP - CSRF
- PHP - FastCGI 程序
- PHP - PDO 擴充套件
- PHP - 內建函式
- PHP 有用資源
- PHP - 速查表
- PHP - 問答
- PHP - 快速指南
- PHP - 線上編譯器
- PHP - 有用資源
- PHP - 討論
PHP mysqli_free_result() 函式
定義和用法
PHP 結果物件(mysqli_result 類)表示 MySQL 結果,由 SELECT 或 DESCRIBE 或 EXPLAIN 查詢返回。
mysqli_free_result() 函式接受結果物件作為引數並釋放與其關聯的記憶體。
語法
mysqli_free_result($result);
引數
序號 | 引數及說明 |
---|---|
1 |
result(必填) 這是表示結果物件的識別符號。 |
返回值
此函式不返回任何值。
PHP 版本
此函式首次引入 PHP 5 版本,並在所有後續版本中均有效。
示例
以下示例演示了 mysqli_free_result() 函式(以過程化風格)的用法:
<?php $con = mysqli_connect("localhost", "root", "password", "mydb"); mysqli_query($con, "CREATE TABLE myplayers(ID INT, First_Name VARCHAR(255), Last_Name VARCHAR(255), Place_Of_Birth VARCHAR(255), Country VARCHAR(255))"); print("Table Created.....\n"); mysqli_query($con, "INSERT INTO myplayers values(1, 'Sikhar', 'Dhawan', 'Delhi', 'India')"); mysqli_query($con, "INSERT INTO myplayers values(2, 'Jonathan', 'Trott', 'CapeTown', 'SouthAfrica')"); mysqli_query($con, "INSERT INTO myplayers values(3, 'Kumara', 'Sangakkara', 'Matale', 'Srilanka')"); print("Record Inserted.....\n"); //Retrieving the contents of the table $res = mysqli_query($con, "SELECT * FROM myplayers"); print("Contents of the resultset...\n"); //Contents of the resultset while ($row = mysqli_fetch_row($res)) { print("ID: ".$row[0]."\n"); print("First_Name: ".$row[1]."\n"); print("Last_Name: ".$row[2]."\n"); print("Place_Of_Birth: ".$row[3]."\n"); print("Country: ".$row[4]."\n"); } //Closing the statement mysqli_free_result($res); //Closing the connection mysqli_close($con); ?>
這將產生以下結果:
Table Created..... Record Inserted..... Contents of the resultset... ID: 1 First_Name: Sikhar Last_Name: Dhawan Place_Of_Birth: Delhi Country: India ID: 2 First_Name: Jonathan Last_Name: Trott Place_Of_Birth: CapeTown Country: SouthAfrica ID: 3 First_Name: Kumara Last_Name: Sangakkara Place_Of_Birth: Matale Country: Srilanka
如果您嘗試在釋放結果後獲取其內容,如下所示:
$con = mysqli_connect("localhost", "root", "password", "mydb"); mysqli_query($con, "CREATE TABLE myplayers(ID INT, First_Name VARCHAR(255), Last_Name VARCHAR(255), Place_Of_Birth VARCHAR(255), Country VARCHAR(255))"); print("Table Created.....\n"); mysqli_query($con, "INSERT INTO myplayers values(1, 'Sikhar', 'Dhawan', 'Delhi', 'India')"); mysqli_query($con, "INSERT INTO myplayers values(2, 'Jonathan', 'Trott', 'CapeTown', 'SouthAfrica')"); mysqli_query($con, "INSERT INTO myplayers values(3, 'Kumara', 'Sangakkara', 'Matale', 'Srilanka')"); print("Record Inserted.....\n"); //Retrieving the contents of the table $res = mysqli_query($con, "SELECT * FROM myplayers"); //Closing the statement mysqli_free_result($res); print("Contents of the resultset...\n"); //Contents of the resultset while ($row = mysqli_fetch_row($res)) { print("ID: ".$row[0]."\n"); print("First_Name: ".$row[1]."\n"); print("Last_Name: ".$row[2]."\n"); print("Place_Of_Birth: ".$row[3]."\n"); print("Country: ".$row[4]."\n"); } //Closing the connection mysqli_close($con);
您將收到如下所示的錯誤:
Table Created..... Record Inserted..... Contents of the resultset... PHP Warning: mysqli_fetch_row(): Couldn't fetch mysqli_result in E:\PHPExamples\procedure_oriented.php on line 19 Warning: mysqli_fetch_row(): Couldn't fetch mysqli_result in E:\PHPExamples\procedure_oriented.php on line 19
示例
在面向物件風格中,此函式的語法為 $result->close(); 以下是此函式在面向物件風格中的示例:
<?php //Creating a connection $con = new mysqli("localhost", "root", "password", "mydb"); $con -> query("CREATE TABLE Test(Name VARCHAR(255), AGE INT)"); $con -> query("insert into Test values('Raju', 25),('Rahman', 30),('Sarmista', 27)"); print("Table Created.....\n"); $stmt = $con -> prepare( "SELECT * FROM Test WHERE Name in(?, ?)"); $stmt -> bind_param("ss", $name1, $name2); $name1 = 'Raju'; $name2 = 'Rahman'; //Executing the statement $stmt->execute(); //Retrieving the result $result = $stmt->get_result(); //Number of rows $count = $result->num_rows; print("Number of rows in the result: ".$count); //Closing the result $result->close(); //Closing the statement $stmt->close(); //Closing the connection $con->close(); ?>
這將產生以下結果:
Table Created..... Number of rows in the result: 2
php_function_reference.htm
廣告