码迷,mamicode.com
首页 > 数据库 > 详细

pymysql

时间:2019-10-16 19:56:49      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:host   func   pre   oca   function   use   connect   ***   time   

* fetchone() :    返回单个的元组,也就是一条记录(row),如果没有结果 , 则返回 None    cu.execute("select user,password from user where user=‘%s‘" %name)
    arr= cur.fetchone()   ----此时 通过 arr[0],arr[1]可以依次访问user,password
* fetchall() :   返回多个元组,即返回多条记录(rows),如果没有结果,则返回 ()   cur.execute("select * from user")***注意:在MySQL中是null,而在Python中则是None

def __init__(self):
self.conn = pymysql.connect(host=‘localhost‘, user=‘root‘, password=‘123‘, database=‘crowfunction1‘, charset=‘utf8‘)
self.db = self.conn.cursor()

def get_goods(self):
# sql = ‘select * from crow_app_period‘
# # print(sql)
# set = self.db.execute(sql)
# print(set)
now_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
start_time = now_time
end_time = now_time
lis = []
tup = (start_time,end_time)
lis.append(tup)
# sql = ‘insert into crow_app_period values(%s,%s)‘
# self.db.execute("insert into crow_app_period(start_time,end_time) values(‘%s‘,‘%s‘)" % (start_time, end_time))
self.db.execute("select end_time from crow_app_period where id=27130")
print(self.db.fetchall() 显示整条信息或者全部信息
# self.db.execute("INSERT INTO crow_app_period(start_time,end_time) values (start_time, end_time)")
# self.db.executemany(sql, lis) # 执行插入数据
# self.db.close()
self.conn.commit()
# self.conn.close()

pymysql

标签:host   func   pre   oca   function   use   connect   ***   time   

原文地址:https://www.cnblogs.com/xingkongzhizhu/p/11687551.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!