Home Database Mysql Tutorial Memory recycling through mysqli extension technology

Memory recycling through mysqli extension technology

May 07, 2017 pm 04:42 PM

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)
Copy after login

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()
Copy after login

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=&#39;center&#39;>序列</p>
                            </td>
                            <td width="156" height="25" bgcolor="#A2D4F4">
                                <p align=&#39;center&#39;>名字</p>
                            </td>
                            <td width="156" height="25" bgcolor="#A2D4F4">
                                <p align=&#39;center&#39;>语文成绩</p>
                            </td>
                            <td width="156" height="25" bgcolor="#A2D4F4">
                                <p align=&#39;center&#39;>数学成绩</p>
                            </td>
                            <td width="156" height="25" bgcolor="#A2D4F4">
                                <p align=&#39;center&#39;>外语成绩</p>
                            </td>
                        </tr>
    <?php
    do{
?>
<tr>
    <td width="156" height="25" bgcolor="#A2D4F4">
        <p align=&#39;center&#39;><?php echo $res[&#39;student_id&#39;];?></p>
    </td>
    <td width="156" height="25" bgcolor="#A2D4F4">
        <p align=&#39;center&#39;><?php echo $res[&#39;name&#39;];?></p>
    </td>
    <td width="156" height="25" bgcolor="#A2D4F4">
        <p align=&#39;center&#39;><?php echo $res[&#39;chinese&#39;];?></p>
    </td>
    <td width="156" height="25" bgcolor="#A2D4F4">
        <p align=&#39;center&#39;><?php echo $res[&#39;mathematics&#39;];?></p>
    </td>
    <td width="156" height="25" bgcolor="#A2D4F4">
        <p align=&#39;center&#39;><?php echo $res[&#39;english&#39;];?></p>
    </td>
</tr>
<?php
    }while($res = mysqli_fetch_array($result, MYSQLI_ASSOC));
}
    $result ->close();
$link ->close();
?>
</table>
(3)实现内存的回收。代码如下:
$result ->close();
$link ->close();
Copy after login

Run the above sample code as shown in the figure below:

Memory recycling through mysqli extension technology

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!

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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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)

Solution to PHP Fatal error: Call to undefined function mysqli_connect() Solution to PHP Fatal error: Call to undefined function mysqli_connect() Jun 23, 2023 am 09:40 AM

When writing web applications using PHP, a MySQL database is often used to store data. PHP provides a way to interact with the MySQL database called MySQLi. However, sometimes when using MySQLi, you will encounter an error message, as shown below: PHPFatalerror:Calltoundefinedfunctionmysqli_connect() This error message means that PHP cannot find my

PHP PDO vs. mysqli: compare and contrast PHP PDO vs. mysqli: compare and contrast Feb 19, 2024 pm 12:24 PM

PDOPDO is an object-oriented database access abstraction layer that provides a unified interface for PHP, allowing you to use the same code to interact with different databases (such as Mysql, postgresql, oracle). PDO hides the complexity of underlying database connections and simplifies database operations. Advantages and Disadvantages Advantages: Unified interface, supports multiple databases, simplifies database operations, reduces development difficulty, provides prepared statements, improves security, supports transaction processing Disadvantages: performance may be slightly lower than native extensions, relies on external libraries, may increase overhead, demo code uses PDO Connect to mysql database: $db=newPDO("mysql:host=localhost;dbnam

What should I do if php cannot connect to mysqli? What should I do if php cannot connect to mysqli? Nov 09, 2022 am 10:07 AM

Solution to php unable to connect to mysqli: 1. Open the "php.ini" file; 2. Find "mysqli.reconnect"; 3. Change "mysqli.reconnect = OFF" to "mysqli.reconnect = on".

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

PHP Warning: mysqli_connect(): (HY000/2002): Solution to Connection refused PHP Warning: mysqli_connect(): (HY000/2002): Solution to Connection refused Jun 23, 2023 am 08:54 AM

If you encounter the following error message when using PHP to connect to a MySQL database: PHPWarning:mysqli_connect():(HY000/2002):Connectionrefused, then you can try to solve this problem by following the steps below. To confirm whether the MySQL service is running normally, you should first check whether the MySQL service is running normally. If the service is not running or fails to start, it may cause a connection refused error. you can

What is the running file of mysql What is the running file of mysql Apr 11, 2023 am 10:38 AM

The running file of mysql is mysqld; mysqld is an executable file, which represents the Mysql server program. Executing this file can directly start a server process; and mysqld_safe is a startup script, which will indirectly call mysqld and also start a monitor. process.

Solution to PHP Fatal error: Call to undefined method mysqli::prepare() Solution to PHP Fatal error: Call to undefined method mysqli::prepare() Jun 23, 2023 am 11:21 AM

When using the mysqli extension to connect and operate a MySQL database, you sometimes encounter the error PHPFatalerror:Calltoundefinedmethodmysqli::prepare(). This error is usually caused by the following reasons: PHP has insufficient support for the mysqli extension; the mysqli extension is not loaded or configured correctly; there are syntax errors in the PHP code; the MySQL server is not correctly configured or running

Detailed explanation of golang memory recycling strategy Detailed explanation of golang memory recycling strategy Apr 24, 2024 am 09:30 AM

Abstract: Go language uses mark-and-sweep algorithm for memory recycling. Strategies include generational GC, escape analysis, concurrent mark and Finalizer. In actual combat, you can use the runtime/debug package to monitor memory usage, such as SetGCPercent() to set the GC frequency, and ReadGCStats() to obtain GC statistics.

See all articles