Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if db connection is closed - php

Tags:

sql

php

Db connectivity is handled by an include.

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

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

Thanks Hamad

like image 905
Hamad Avatar asked Jun 13 '10 16:06

Hamad


2 Answers

is_resource($con)

gives false if the connection is closed.

like image 88
Artefacto Avatar answered Sep 30 '22 05:09

Artefacto


You can use mysql_ping($con);

Depending on your PHP version, the older ones would reopen the connection if it was closed automatically. It shouldn't do that in PHP5

like image 25
Aaron Harun Avatar answered Sep 30 '22 05:09

Aaron Harun