Realize memory recycling through mysqli extension technology
In order to effectively utilize the memory space of the server, when obtaining a larger result set, once the operation is completed, there It is necessary to recycle the memory required for the collection. Since mysqli technology can adopt both object-oriented and process-oriented programming methods, there are two corresponding memory recycling methods. This example will be used to explain the role of the memory recycling mechanism in the project development process. Value and use.
In the previous article "Using mysqli expansion technology to implement multiple data table queries", we introduced the mysqli expansion technology to implement multiple data table queries, so our article today Mainly introduce to you mysqli expansion technology to achieve memory recycling!
Technical Points
In order to cater to programmers with different development habits, PHP provides both object-oriented and process-oriented mysqli extension technologies. Programming, so there are two corresponding ways to implement memory recycling. If you use process-oriented programming, you can achieve memory recycling through the following function:
bool mysqli_close ( object link)
link refers to the database connection handle returned by the mysqli_connect() function.
If object-oriented programming is adopted, it can be achieved through the following statement:
link->close()
link refers to the object instantiated by PHP's predefined mysqli class.
Implementation process
1) Create the conn.php file to connect to the MySQL database.
(2) Display the scores of all students in the class through do...while loop. The code is as follows:
<?php header("Content-Type:text/html; charset=utf-8"); $link = mysqli_connect("localhost", "root", "root"); $conn = mysqli_select_db($link, "php_cn"); $sql = "select * from student,score where student.id=score.id"; $result = mysqli_query($link, $sql); $res = mysqli_fetch_array($result, MYSQLI_ASSOC); if(!$res) { echo "没有找到你要的信息"; }else{ ?> <table width="600" height="50" border="0" align="center" cellspacing="1" cellpadding="0"> <tr> <td width="156" height="25" bgcolor="#A2D4F4"> <p align='center'>序列</p> </td> <td width="156" height="25" bgcolor="#A2D4F4"> <p align='center'>名字</p> </td> <td width="156" height="25" bgcolor="#A2D4F4"> <p align='center'>语文成绩</p> </td> <td width="156" height="25" bgcolor="#A2D4F4"> <p align='center'>数学成绩</p> </td> <td width="156" height="25" bgcolor="#A2D4F4"> <p align='center'>外语成绩</p> </td> </tr> <?php do{ ?> <tr> <td width="156" height="25" bgcolor="#A2D4F4"> <p align='center'><?php echo $res['student_id'];?></p> </td> <td width="156" height="25" bgcolor="#A2D4F4"> <p align='center'><?php echo $res['name'];?></p> </td> <td width="156" height="25" bgcolor="#A2D4F4"> <p align='center'><?php echo $res['chinese'];?></p> </td> <td width="156" height="25" bgcolor="#A2D4F4"> <p align='center'><?php echo $res['mathematics'];?></p> </td> <td width="156" height="25" bgcolor="#A2D4F4"> <p align='center'><?php echo $res['english'];?></p> </td> </tr> <?php }while($res = mysqli_fetch_array($result, MYSQLI_ASSOC)); } $result ->close(); $link ->close(); ?> </table> (3)实现内存的回收。代码如下: $result ->close(); $link ->close();
Run the above sample code as shown in the figure below:
This is the end of the mysqli expansion technology. I believe that friends are interested in it. You have a certain understanding of the expansion technology of mysqli. You can try the knowledge you learned in our topic locally!
【Related tutorial recommendations】
1. Relevant topic recommendations: "php operating mysql database"
2.【 MYSQL Online Free Video Tutorial】
3. Recommended related video courses: "Elementary MySQLi Extension Library Video Tutorial 》
The above is the detailed content of Memory recycling through mysqli extension technology. For more information, please follow other related articles on the PHP Chinese website!