亚洲区国产区激情区无码区,国产成人mv视频在线观看,国产A毛片AAAAAA,亚洲精品国产首次亮相在线

PHP mysqli_stmt_free_result() 函數用法及示例

PHP MySQLi 參考手冊

mysqli_stmt_free_result()函數釋放給定語句句柄的存儲結果內存。

定義和用法

mysqli_stmt_free_result()函數接受(準備好的)語句對象作為參數,并釋放存儲給定語句結果的內存(使用mysqli_stmt_store_result()函數存儲結果時)。

語法

mysqli_stmt_free_result($stmt);

參數

序號參數及說明
1

con(必需)

這是表示準備好的語句的對象。

返回值

PHP mysqli_stmt_free_result()函數不返回任何值。

PHP版本

此函數最初是在PHP版本5中引入的,并且可以在所有更高版本中使用。

在線示例

以下示例演示了mysqli_stmt_free_result()函數的用法(面向過程風格),返回釋放結果后的行數:

<?php
   $con = mysqli_connect("localhost", "root", "password", "mydb");

   mysqli_query($con, "CREATE TABLE Test(Name VARCHAR(255), AGE INT)");
   mysqli_query($con, "insert into Test values('Raju', 25),('Rahman', 30),('Sarmista', 27)");
   print("創(chuàng)建表.....\n");

   //讀取記錄
   $stmt = mysqli_prepare($con, "SELECT * FROM Test");

   //執(zhí)行語句
   mysqli_stmt_execute($stmt);

   //存儲結果
   mysqli_stmt_store_result($stmt);

   //行數
   $count = mysqli_stmt_num_rows($stmt);
   print("表中的行數: ".$count."\n");

   //Freeing the resultset
   mysqli_stmt_free_result($stmt);

   $count = mysqli_stmt_num_rows($stmt);
   print("釋放結果后的行數: ".$count."\n");

   //結束語句
   mysqli_stmt_close($stmt);

   //關閉連接
   mysqli_close($con);
?>

輸出結果

創(chuàng)建表.....
表中的行數: 3
釋放結果后的行數: 0

在線示例

在面向對象風格中,此函數的語法為$stmt->free_result();。以下是面向對象風格中此函數的示例;

<?php
   //建立連接
   $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("創(chuàng)建表.....\n");

   $stmt = $con -> prepare( "SELECT * FROM Test");

   //執(zhí)行語句
   $stmt->execute();

   //存儲結果
   $stmt->store_result();
   print("存儲結果行數 ".$stmt ->num_rows);

   //釋放結果集內存
   $stmt->free_result();

   //結束語句
   $stmt->close();

   //關閉連接
   $con->close();
?>

輸出結果

創(chuàng)建表.....
存儲結果行數 : 3

PHP MySQLi 參考手冊