Last active
December 16, 2015 02:19
-
-
Save stormsson/5361680 to your computer and use it in GitHub Desktop.
Python - Default Header with Mysql DB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import MySQLdb as mdb | |
import MySQLdb.cursors | |
class dbDevConfiguration: | |
host = "localhost" | |
username = "root" | |
password = "root" | |
db = "dbname-dev" | |
class dbProductionConfiguration: | |
host = "localhost" | |
username = "root" | |
password = "root" | |
db = "dbname-prod" | |
_con = None | |
try: | |
_con = mdb.connect( dbDevConfiguration.host, dbDevConfiguration.username, dbDevConfiguration.password, dbDevConfiguration.db,cursorclass=MySQLdb.cursors.DictCursor) | |
except Exception, e: | |
pass | |
if(_con ==None): | |
try: | |
_con = mdb.connect( dbProductionConfiguration.host, dbProductionConfiguration.username, dbProductionConfiguration.password, dbProductionConfiguration.db,cursorclass=MySQLdb.cursors.DictCursor) | |
except Exception: | |
raise Exception("connessione con dev o prod fallita") | |
def getConnection(): | |
global _con | |
return _con |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment