Imagine the simple snippet below:
<?
mysql_close();
?>
This will obviously output the following warni开发者_JAVA百科ng (may look different depending on what version of php_mysql(i) you are using):
mysql_close(): no MySQL-Link resource supplied in .....
As there is no link open.
Is there a way in php to test if a mysql link is already established or not?
Thanks!
Note, have been getting a few comments regarding the use of mysql_close(). I just used that as an example. Furthermore, there are (many) situations when the use of mysql_close() is appropriate.
If you keep track of the resource identifier, you can use if ($link)
which will get destroyed if you call mysql_close and then it will no longer evaluate true.
well i'm not sure but see the answer here
Is closing the mysql connection important?
From the documentation:
Note: The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling mysql_close().
If you need reconnect to mysql, look at this function: http://www.php.net/manual/ru/function.mysql-ping.php
精彩评论