PHP mysqli_free_result () and mysqli_fetch_array () functions, mysqlifetcharray

Source: Internet
Author: User

PHP mysqli_free_result () and mysqli_fetch_array () functions, mysqlifetcharray

PHP mysqli_free_result () and mysqli_fetch_array () Functions

Mysql_free_result () is called only when considering how much memory will be occupied when a large result set is returned. After the script is completed, all associated memory will be automatically released.

After executing the SELECT statement, releasing the cursor memory is a good habit. . You can use the PHP function mysql_free_result () to release the memory.

// Define the header file. The character format is header ("Content-type: text/html; charset = UTF-8"); error_reporting (ERR_ALL &~ E_NOTICE); // defines the connection information of the local server $ servername = "localhost"; $ username = "root"; $ password = "admin"; $ dbname = "test "; // local connection $ conn = mysqli_connect ($ servername, $ username, $ password, $ dbname) or die (mysqli_error ()); // information to be queried $ SQL = "SELECT firstname, lastname, email FROM hello"; $ result = mysqli_query ($ conn, $ SQL ); // determine whether the string is successfully executed if ($ result) {while ($ row = mysqli_fetch_array ($ result, MYSQLI_ASSOC) {echo $ row ["firstname"]. "". $ row [ "Lastname"]. "". $ row ["email"]. "<br>"; echo "

Note: In addition to mysqli_free_result, I also need 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 an 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 an index array. The key of the array is a numerical index such as, and 4. You can only use this method in this way:

$ Row [0], row [1]...

3: MYSQLI_BOTH. The returned result array contains both the field index and the numeric index. You can use both of the above two indexes.

The above are the materials for PHPmysqli_free_result () and mysqli_fetch_array (). We will continue to add relevant materials later. Thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.