zoukankan      html  css  js  c++  java
  • 【python】pymysql库的简单使用

    import pymysql
    #连接数据库
    class lgx:
    def __init__(self):
    self.connect1 = pymysql.connect(host='',
    # 地址
    user='',
    # 用户名
    password='',
    #密码
    db='',
    # 数据库名
    charset='utf8',
    #格式处理
    cursorclass=pymysql.cursors.DictCursor,
    #返回内容字典化,便于查看浏览,不加的话返回元组
    autocommit=False
    #阻断自动提交,防止出错时产生脏数据
    )

    def lgxdsb(self):
    # 做一个光标
    cursor1 = self.connect1.cursor()
    #写入想要执行数据库操作语句
    sql="""
    select id,site_id,error_code from union_hybrid_event_log_test where id=1;
    """
    # 运行这个语句
    cursor1.execute(sql)
    # 涉及到修改数据库时要加上·提交commit()
    # connect1.commit()
    # 输出查询后储存在内部的数据
    print(cursor1.fetchall())
    # 关闭光标
    cursor1.close()
    # 关闭数据库连接
    self.connect1.close()
    if __name__ == '__main__':
    SQL=lgx().lgxdsb()
  • 相关阅读:
    phpdocumentor生成代码注释文档(linux)
    phpstorm扩展
    es教程
    康威定律
    k8s
    tidb调研
    netty 在线教程
    McQueenRPC源码阅读
    DIY一些基于netty的开源框架
    性能测试
  • 原文地址:https://www.cnblogs.com/luoguoxing/p/15118990.html
Copyright © 2011-2022 走看看