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); //定义本地服务器连接信息 $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); //判断字符串是否执行成功 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!"); } //释放游标内存 mysqli_free_result($result); //关闭数据库连接 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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
