|
|
|
@ -17,6 +17,7 @@ class ORM: |
|
|
|
|
__DB_CUR = None |
|
|
|
|
__DB_ERR = None |
|
|
|
|
__DB_CNF = '/etc/my.cnf' |
|
|
|
|
__DB_TIMEOUT=1 |
|
|
|
|
__DB_SOCKET = '/www/server/mysql/mysql.sock' |
|
|
|
|
|
|
|
|
|
__DB_CHARSET = "utf8" |
|
|
|
@ -30,37 +31,36 @@ class ORM: |
|
|
|
|
try: |
|
|
|
|
self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, |
|
|
|
|
database=self.__DB_NAME, |
|
|
|
|
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=5, |
|
|
|
|
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT, |
|
|
|
|
cursorclass=pymysql.cursors.DictCursor) |
|
|
|
|
except Exception as e: |
|
|
|
|
self.__DB_HOST = '127.0.0.1' |
|
|
|
|
self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, |
|
|
|
|
database=self.__DB_NAME, |
|
|
|
|
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, |
|
|
|
|
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT, |
|
|
|
|
cursorclass=pymysql.cursors.DictCursor) |
|
|
|
|
elif os.path.exists(self.__DB_SOCKET): |
|
|
|
|
try: |
|
|
|
|
self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, |
|
|
|
|
database=self.__DB_NAME, |
|
|
|
|
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, |
|
|
|
|
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT, |
|
|
|
|
unix_socket=self.__DB_SOCKET, cursorclass=pymysql.cursors.DictCursor) |
|
|
|
|
except Exception as e: |
|
|
|
|
self.__DB_HOST = '127.0.0.1' |
|
|
|
|
self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, |
|
|
|
|
database=self.__DB_NAME, |
|
|
|
|
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, |
|
|
|
|
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT, |
|
|
|
|
unix_socket=self.__DB_SOCKET, cursorclass=pymysql.cursors.DictCursor) |
|
|
|
|
else: |
|
|
|
|
try: |
|
|
|
|
self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, |
|
|
|
|
database=self.__DB_NAME, |
|
|
|
|
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, |
|
|
|
|
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT, |
|
|
|
|
cursorclass=pymysql.cursors.DictCursor) |
|
|
|
|
except Exception as e: |
|
|
|
|
self.__DB_HOST = '127.0.0.1' |
|
|
|
|
self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, |
|
|
|
|
database=self.__DB_NAME, |
|
|
|
|
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1, |
|
|
|
|
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT, |
|
|
|
|
cursorclass=pymysql.cursors.DictCursor) |
|
|
|
|
|
|
|
|
|
self.__DB_CUR = self.__DB_CONN.cursor() |
|
|
|
@ -93,6 +93,10 @@ class ORM: |
|
|
|
|
def getPwd(self): |
|
|
|
|
return self.__DB_PASS |
|
|
|
|
|
|
|
|
|
def setTimeout(self, timeout = 1): |
|
|
|
|
self.__DB_TIMEOUT = timeout |
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
def setDbName(self, name): |
|
|
|
|
self.__DB_NAME = name |
|
|
|
|
|
|
|
|
|