Check if db connection is closed - php

Db connectivity is handled with include.

I want to run this command: mysql_close ($ CON);

Only if we have a connection. Something like isset ()?

Thanks Hamad

+5
source share
4 answers
is_resource($con)

gives falseif the connection is closed.

+8
source

you can use mysql_ping($con);

Depending on your version of PHP, seniors will open the connection if it was automatically closed. This should not be done in PHP5

+2
source

, mysql_ping, , .

0

@Artefacto, , $con , , :

Notice: Undefined variable: con in...

:

if ( is_resource($con)) {
     mysqli_close($con);
}

, mysql_ping($con) .

0
source

All Articles