Current Location: Home> Function Categories> mysql_free_result

mysql_free_result

Free the result memory.
Name:mysql_free_result
Category:Uncategorized
Programming Language:php
One-line Description:Free the memory occupied by the result set

Function name: mysql_free_result()

Function description: mysql_free_result() Frees the memory occupied by the result set.

Applicable version: PHP 4, PHP 5, PHP 7

usage:

mysql_free_result(resource $result): bool

parameter:

  • $result: Required. The result set resource returned by the mysql_query() function.

Return value:

  • Returns true on success, and false on failure.

Example:

 <?php // 连接数据库$link = mysql_connect('localhost', 'username', 'password'); if (!$link) { die('连接数据库失败: ' . mysql_error()); } // 选择数据库$db_selected = mysql_select_db('database_name', $link); if (!$db_selected) { die ('选择数据库失败: ' . mysql_error()); } // 执行查询$query = "SELECT * FROM users"; $result = mysql_query($query); if (!$result) { die('查询失败: ' . mysql_error()); } // 处理结果集while ($row = mysql_fetch_assoc($result)) { echo $row['name'] . '<br>'; } // 释放结果集占用的内存mysql_free_result($result); // 关闭数据库连接mysql_close($link); ?>

Notes:

  • After using the result set, the mysql_free_result() function should be called to free the memory occupied by the result set to avoid memory leakage.
  • After PHP 5.5.0, it is recommended to use the mysqli or PDO extension instead of the mysql function, because the mysql function has been removed in PHP 7.
Similar Functions
Popular Articles