zoukankan      html  css  js  c++  java
  • pymysql

    * 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()
  • 相关阅读:
    sql:drop、delete、truncate的区别
    pgsql:插入数据,存在就更新,不存在就插入
    sql:多表连接查询
    克隆模式
    canvas 实现星空闪烁的效果,鼠标滑动,连接周围的点
    JS微信网页图片预览可放大缩小
    muduo_base 02 (Atomic)
    muduo_base 01 (Timestamp)
    select/poll/epoll
    socket编程(二)
  • 原文地址:https://www.cnblogs.com/xingkongzhizhu/p/11687551.html
Copyright © 2011-2022 走看看