Where I must include and how / when execute mysql_close($link);

function getListFetchApp($query='') {


   global $link, $db_selected;

   mysql_query("SET NAMES utf8"); 
   $result = mysql_query($query);

   if($result === false) { 

	 return false;  



   $rows = Array();

   while ($row = mysql_fetch_assoc($result)) {

     $rows[] = $row;

   mysql_free_result($result);   //  http://php.net/manual/en/function.mysql-free-result.php
   return $rows;


i use this to execute my queries, well where I must include and how / when execute mysql_close($link);

Why would you want to close the connection in a function? What if you want another function to make a database call? It’s not necessary to close a connection and reopen a new connection on the same page. It’s good for practice, but PHP already closes connections by default.

Also, mysql_* are deprecated and have been removed from PHP 5.5 + It is best to switch to mysqli_* or PDO now while you are still trying to figure out why you shouldn’t close the connection manually.

It is also recommend that if you choose mysqli_* or PDO, you should also be learning how to use prepared statements. mysqli_* is NOT like mysql_*. Don’t just assume that you can append an i after mysql and you’d be ok. You have to actually learn how to use mysqli_* as it has more steps and procedures than mysql_*.

No longer deprecated - was completely removed a month ago.

1 Like

Alright, so I guess I can say removed completely now instead of deprecated.

Well ‘deprecated’ mean obsolete now and to be removed later.

So once it actually is removed it is no longer deprecated as it no longer exists at all.

With regard to the mysql_ interface, it is deprecated in PHP 5.5 (security patch support ends July 2016) and in PHP 5.6 (full support ends July 2016, security patch support ends July 2017) and no longer exists in PHP 7 (the current version as of last month).

1 Like

Alright, that makes sense.

If my php version is old 5.3 or 5.4, and wanted to use this script mysql_free_result () … can used for insert update and delete too … not just select?

You want to not use it at all.
Though your PHP version may be “old” the DEPRECATED mysql_ functions are even older.


  			mysqli 	PDO MySQL
PHP version introduced	5.0 	5.0 Prior to 3.0
Included with PHP 5.x	yes 	yes Yes


Frees the memory associated with the result.
You should always free your result with mysqli_free_result(), when your result object is not needed anymore.

To free a result there first needs to be a result.

Ok get error if execute delete query with mysql_free_result. …? Or not error…?

What was the error message?

I did not tried
it will give error in that case?

Well, try it (local, not live) and find out :wink:

You mean you want to use a version of PHP that is no longer supported and may contain security holes? PHP 5.5 is the oldest version that will still receive security patches.

Both mysqli and PDO were introduced in July 2004 and so have been around for over 11 years now. The old mysql interface was declared to be obsolete nearly three years ago after people had been given eight years to upgrade to one of the far more powerful and secure replacements and giving everyone notice that they should convert over immediately if they hadn’t already as the old interface was going to be removed soon (which actually happened last month).


Quick @felgall, PDO, not PDP. lol

Oops - fixed - thanks

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.