Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a MySQL connection is closed in Python?

Tags:

python

mysql

The question says everything. How can I check if my MySQL connection is closed in Python?

I'm using MySQLdb, see http://mysql-python.sourceforge.net/

like image 204
Kent Avatar asked Jul 26 '10 13:07

Kent


People also ask

How do I check if MySQL is closed in Python?

open attribute will tell you whether the connection has been explicitly closed or whether a remote close has been detected.

How do I close a MySQL connection?

The close() / mysqli_close() function closes a previously opened database connection.


1 Answers

The Connection.open field will be 1 if the connection is open and 0 otherwise. So you can say

if conn.open:     # do something 
like image 120
Eli Courtwright Avatar answered Oct 05 '22 03:10

Eli Courtwright