Just starting to get to grips with python and MySQLdb and was wondering
Where is the best play to put a try/catch block for the connection to MySQL. At the MySQLdb.connect point? Also should there be one when ever i query?
What exceptions should i be catching on any of these blocks?
thanks for any help
Cheers Mark
MySQLdb module, a popular interface with MySQL is not compatible with Python 3.
InterfaceError: When database connection fails for some reason, MySQLdb will raise an InterfaceError. Note InterfaceError only get raise when there is internal problem in connection to the database, MySQLdb will not raise InterfaceError because of wrong database name or password.
MySQLdb is an interface for connecting to a MySQL database server from Python. It implements the Python Database API v2. 0 and is built on top of the MySQL C API. Packages to Install. mysql-connector-python mysql-python.
Catch the MySQLdb.Error, while connecting and while executing query
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With