赞
踩
废话不多说,直接上代码
- # -*- coding: UTF-8 -*-
- # @Time : 2018/8/31 8:23
- # @Author : wuming.wang
- # @Email : wuming.wang@tinno.com
- # @File : DiffDatabase.py
- # @Software: PyCharm
-
- import MySQLdb
- import os
- import sys
- reload(sys)
- sys.setdefaultencoding('utf-8')
-
- base_dir = os.path.abspath(os.path.dirname(__file__))
-
-
- class Diff:
- def __init__(self):
- self.test_host = '192.168.**.***'
- self.test_user_name = '****'
- self.test_password = '****'
- self.test_port = '3306'
- self.test_dbname = '****'
-
- self.online_host = '192.***.**.**'
- self.online_user_name = '**'
- self.online_password = '***'
- self.online_port = '3306'
- self.online_dbname = '*****'
-
- def get_data(self, env, sql):
- if env == "test":
- conn = MySQLdb.connect(self.test_host, self.test_user_name, self.test_password, self.test_dbname,
- charset="utf8")
- else:
- conn = MySQLdb.connect(self.online_host, self.online_user_name, self.online_password, self.online_dbname,
- charset="utf8")
-
- cur = conn.cursor()
- cur.execute(sql)
-
- results = cur.fetchall() # 搜取所有结果
- cur.close()
- conn.close()
- return results
-
- # 把返回的嵌套元素转换为列表
- de
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。