PyMysql

作者: __construct | 来源:发表于2017-11-24 15:52 被阅读0次
    import pymysql
    
    #  连接数据库
    con = pymysql.connect(
        host = 'localhost',
        user = 'root',
        password = '',
        db = 'python',
        charset = 'utf8'
    )
    
    try:
        # 获取会话指针
        with con.cursor() as cursor:
            sql = "select * from code"
            # 得到总记录数
            count = cursor.execute(sql)
            print(count)
            # 获得所有数据
            res = cursor.fetchall()
            for i in res:
                print(i)
    
    finally:
        con.close()

    相关文章

      网友评论

          本文标题:PyMysql

          本文链接:https://www.haomeiwen.com/subject/iolfbxtx.html