PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




mysql_free_result() Function for PHP


Tutorials »Php »

Topic

What is mysql_free_result() function in PHP?
How does mysql_free_result() works?




Explanation

Mysql function mysql_free_result() will free all memory associated with the result identifier result.

Syntax

bool mysql_free_result ( resource result)


This mysql_free_result() returns TRUE on success, or FALSE on failure.

mysql_free_result() frees the memory used by a result handle, deleting the result handle in the process. mysql_free_result() only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. In most cases, this function is unnecessary; PHP's memory-management system automatically releases the memory used by result handles at the end of the script execution.

Example:


<?php

//Attempt to connect to the default database server
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");

//select database
mysql_select_db("my_database");

//execute simple query
$result = mysql_query("SELECT * FROM mytable");

$row = mysql_fetch_array($result,MYSQL_BOTH);

//print result
print_r($row);

//free the result resource
mysql_free_result($result);

?>



RESULT:

Array (
[0] => 76 [id] => 76
[1] => Nicolus [name] => Nicolus
[2] => selected [status] => selected
)


In the above code mysql_free_result() function is used to free the result handle '$result'. When the result handle is accessed after deleting the result resource using mysql_free_result() function will result in error.

Example:


<?php

//Attempt to connect to the default database server
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");

//select database
mysql_select_db("my_database");

//execute simple query
$result = mysql_query("SELECT * FROM mytable");

$row = mysql_fetch_array($result,MYSQL_BOTH);

//print result
print_r($row);

//free the result resource
mysql_free_result($result);

$row = mysql_fetch_array($result,MYSQL_BOTH);

//print result
print_r($row);

?>



RESULT:

mysql_fetch_array(): is not a valid MySQL result resource





Other Links

web hosting