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!