国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home 類庫下載 PHP類庫 PHP mysqli_free_result() and mysqli_fetch_array() functions

PHP mysqli_free_result() and mysqli_fetch_array() functions

Oct 09, 2016 pm 01:02 PM

mysql_free_result() only needs to be called when considering how much memory it will take up when returning a very large result set. All associated memory will be automatically released after the script ends.

After we execute the SELECT statement, it is a good habit to release the cursor memory. . Memory release can be achieved through the PHP function mysql_free_result().

//定義頭文件,字符格式
 header("Content-type:text/html;charset=utf-8");
 error_reporting(ERR_ALL & ~ E_NOTICE);
 
 //定義本地服務(wù)器連接信息
 $servername="localhost";
 $username="root";
 $password="admin";
 $dbname="test";
 
 //本地連接
 $conn=mysqli_connect($servername,$username,$password,$dbname)or die(mysqli_error());
 
//要查詢的信息
$sql="SELECT firstname,lastname,email FROM hello";
$result=mysqli_query($conn,$sql);
 
//判斷字符串是否執(zhí)行成功
if($result){
 while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))  {
    echo $row["firstname"]." ".$row["lastname"]." ".$row["email"]."<br>";
    echo "<hr>";
  }
}else{
  die("fetch data failed!");
}
 
//釋放游標(biāo)內(nèi)存
mysqli_free_result($result);
//關(guān)閉數(shù)據(jù)庫連接
mysqli_close($conn);

Note: In addition to talking about mysqli_free_result, I also want to mention the second parameter of the mysqli_fetch_array() function

mysqli_fetch_array(result,resulttype)
resulttype parameter:
1: MYSQLI_ASSOC, the returned result array is associated Array, the key of the array is the corresponding field name, you can use it like this:
row['firstname'], row['lastname']...

2: MYSQLI_NUM, the returned result array is the index array, The keys of the array are numeric indexes such as 0,1,2,3,4. You can only use it like this:
$row[0], row[1]...

3: MYSQLI_BOTH, the returned result array There are both field indexes and numeric indexes in . When you use it, both of the above can be used.


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)