# coding:utf-8
import pymysql
class MysqlUtil(object):
def __init__(self):
# 获取数据库连接
self.db = pymysql.connect('192.168.18.183', 'root', 'root', 'ygp_sms')
#指定查询 返回类型
self.cursor = self.db.cursor(pymysql.cursors.DictCursor)
def execute(self, sql):
print('执行数据了')
return self.cursor.execute(sql)
def save(self, save):
i = 1
for s in save:
try:
sql = "insert into demomsg01(phone,y,n,time ,s ) values ('"+s['phone']+"','"+s['y']+"','"+s['n']+"','"+s['time']+"','"+s['s']+"')"
self.execute(sql)
self.db.commit()
s1 = '保存了 %d 条数据了' %i
print(s1)
i = i + 1
except BaseException as e:
print(e)
def save02(self, save):
i = 1
for s in save:
try:
sql = "insert into demomsg02(phone,y,n,time ,s ) values ('" + s['phone'] + "','" + s['y'] + "','" + s[
'n'] + "','" + s['time'] + "','" + s['s'] + "')"
self.execute(sql)
self.db.commit()
s1 = '保存了 %d 条数据了' % i
print(s1)
i = i + 1
except BaseException as e:
print(e)
def query(self, sql):
#查询方法
return self.cursor.execute(sql)
版权归属:
天马
许可协议:
本文使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
评论区