• pymsql



    pymysql模块:
    pip3 install pymysql -i https://pypi.douban.com/simple
    Python模块:对数据库进行操作(SQL语句)

    1. Python实现用户登录
    2. MySQL保存数据


    - 连接、关闭(游标)
    - execute() -- SQL注入
    - 增删改: conn.commit()
    - fetchone fetchall
    - 获取插入数据自增ID

    # 增加,删,该
    # conn = pymysql.connect(host="localhost",user='root',password='',database="db666")
    # cursor = conn.cursor()
    # sql = "insert into userinfo(username,password) values('root','123123')"
    # 受影响的行数
    # r = cursor.execute(sql)
    # # ******
    # conn.commit()
    # cursor.close()
    # conn.close()

    # conn = pymysql.connect(host="localhost",user='root',password='',database="db666")
    # cursor = conn.cursor()
    # # sql = "insert into userinfo(username,password) values(%s,%s)"
    # # cursor.execute(sql,(user,pwd,))
    #
    # sql = "insert into userinfo(username,password) values(%s,%s)"
    # # 受影响的行数
    # r = cursor.executemany(sql,[('egon','sb'),('laoyao','BS')])
    # # ******
    # conn.commit()
    # cursor.close()
    # conn.close()

    # 查
    # conn = pymysql.connect(host="localhost",user='root',password='',database="db666")
    # cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
    # sql = "select * from userinfo"
    # cursor.execute(sql)
    # cursor.scroll(1,mode='relative') # 相对当前位置移动
    # cursor.scroll(2,mode='absolute') # 相对绝对位置移动
    # result = cursor.fetchone()
    # print(result)
    # result = cursor.fetchone()
    # print(result)
    # result = cursor.fetchone()
    # print(result)
    # result = cursor.fetchall()
    # print(result)
    # result = cursor.fetchmany(4)
    # print(result)
    # cursor.close()
    # conn.close()

    # 新插入数据的自增ID: cursor.lastrowid
    # import pymysql
    # conn = pymysql.connect(host="localhost",user='root',password='',database="db666")
    # cursor = conn.cursor()
    # sql = "insert into userinfo(username,password) values('asdfasdf','123123')"
    # cursor.execute(sql)
    # conn.commit()
    # print(cursor.lastrowid)
    # cursor.close()
    # conn.close()
  • 相关阅读:
    lines-HDU5124(区间处理 +离散化)
    Reorder the Books-HDU5500
    Bad Hair Day-POJ3250(简单的入栈出栈)
    Count the Colors-ZOJ1610(线段树区间求)
    Just a Hook-HDU1698(线段树求区间)
    Mayor's posters-POJ2528(线段树+离散化)
    A Simple Problem with Integers-POJ3468
    Strongly connected-HDU4635
    Caocao's Bridges-HDU4738(Tarjin+求桥)
    Warm up-HUD4612(树的直径+Tarjin缩点)
  • 原文地址:https://www.cnblogs.com/duhong0520/p/11294686.html
Copyright © 2020-2023  润新知