开发者

PHP mysql : possible to check if a link is open?

开发者 https://www.devze.com 2023-04-06 09:57 出处:网络
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 us

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

0

精彩评论

暂无评论...
验证码 换一张
取 消