|
|
|
@ -4,7 +4,7 @@ import re |
|
|
|
|
import os |
|
|
|
|
import sys |
|
|
|
|
|
|
|
|
|
sys.path.append("/usr/local/lib/python2.7/site-packages") |
|
|
|
|
# sys.path.append("/usr/local/lib/python3.6/site-packages") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class mysqlDb: |
|
|
|
@ -24,20 +24,20 @@ class mysqlDb: |
|
|
|
|
socket = '/tmp/mysql.sock' |
|
|
|
|
try: |
|
|
|
|
import MySQLdb |
|
|
|
|
except Exception, ex: |
|
|
|
|
except Exception as ex: |
|
|
|
|
self.__DB_ERR = ex |
|
|
|
|
return False |
|
|
|
|
try: |
|
|
|
|
self.__DB_CONN = MySQLdb.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, |
|
|
|
|
port=self.__DB_PORT, db=self.__DB_NAME, charset="utf8", connect_timeout=10, unix_socket=socket) |
|
|
|
|
except MySQLdb.Error, e: |
|
|
|
|
except MySQLdb.Error as e: |
|
|
|
|
self.__DB_HOST = '127.0.0.1' |
|
|
|
|
self.__DB_CONN = MySQLdb.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, |
|
|
|
|
port=self.__DB_PORT, db=self.__DB_NAME, charset="utf8", connect_timeout=10, unix_socket=socket) |
|
|
|
|
self.__DB_CUR = self.__DB_CONN.cursor() |
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
except MySQLdb.Error, e: |
|
|
|
|
except MySQLdb.Error as e: |
|
|
|
|
self.__DB_ERR = e |
|
|
|
|
return False |
|
|
|
|
|
|
|
|
@ -68,7 +68,7 @@ class mysqlDb: |
|
|
|
|
self.__DB_CONN.commit() |
|
|
|
|
self.__Close() |
|
|
|
|
return result |
|
|
|
|
except Exception, ex: |
|
|
|
|
except Exception as ex: |
|
|
|
|
return ex |
|
|
|
|
|
|
|
|
|
def query(self, sql): |
|
|
|
@ -82,7 +82,7 @@ class mysqlDb: |
|
|
|
|
data = map(list, result) |
|
|
|
|
self.__Close() |
|
|
|
|
return data |
|
|
|
|
except Exception, ex: |
|
|
|
|
except Exception as ex: |
|
|
|
|
return ex |
|
|
|
|
|
|
|
|
|
# 关闭连接 |
|
|
|
|