zoukankan      html  css  js  c++  java
  • pymysql的用法

    import pymysql
    
    user = input("username:")
    pwd = input("password:")
    
    conn = pymysql.connect(host="localhost",user='root',password='',database="db666")
    cursor = conn.cursor()
    sql = "select * from userinfo where username='%s' and password='%s'" %(user,pwd,)
    # select * from userinfo where username='uu' or 1=1 -- ' and password='%s'
    cursor.execute(sql)
    result = cursor.fetchone()
    cursor.close()
    conn.close()
    
    if result:
        print('登录成功')
    else:
        print('登录失败')
    import pymysql
    
    user = input("username:")
    pwd = input("password:")
    
    conn = pymysql.connect(host="localhost",user='root',password='',database="db666")
    cursor = conn.cursor()
    sql = "select * from userinfo where username=%s and password=%s"
    cursor.execute(sql,user,pwd)
    # cursor.execute(sql,[user,pwd])
    # cursor.execute(sql,{'u':user,'p':pwd})
    result = cursor.fetchone()
    cursor.close()
    conn.close()
    if result:
        print('登录成功')
    else:
        print('登录失败')
    import pymysql
    
    # 增加,删,该
    # 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()
  • 相关阅读:
    java中Calendar类里面的月份是月份数减一。
    hdu oj
    存在重复元素
    杨辉三角
    删除链表的倒数第n个结点
    相交链表
    环形链表 II
    环形链表
    至少是其他数字两倍的最大数
    寻找数组的中心索引
  • 原文地址:https://www.cnblogs.com/dalishusheng/p/13267511.html
Copyright © 2011-2022 走看看