* 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()