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_*.
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).
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).