import pymysql conn=pymysql.connect( host='localhoset', port=3306, user='root', password='' database='day46' charset='utf8' ) cur=conn.cursor() sql='insert into dep(name)values(%s)' cur.execute(sql,('yyyy',)) cur.executemany(sql.[('aa'),('bb'),('ccc')]) conn.commit() cur.closer() conn.close() import pymysql #用户输入:egon''-- assasdasdasd #用户输入:xxxxx'' or 1=1 --hello name=input('name:').strip() password=input('password:').strip() conn=pymysql.connect( host='localhost', port=3360, user='root' password=' ' databaase='day46' charset='utf8’ ) cur=conn.cursor() #sql='select*from userinfo where user='%s' and password='%s';'%(name,password) #print(sql) #sql=select *from userinfo where user='egon'--'and password='';' #sql='select*from userinfo where user='xxxx' or 1=1--hello 'and password='''';' sql='select *from userinfo where user =%s and password=%s;' res =cur.execute(sql,(name,password)) print(res) cur.close() conn.close() if res: print('登录成功') else: print('登录失败')
import pymysql conn=pymysql.connect( hose='localhost', port=3306, user='root' password='' database='day46' charset='utf8' ) cur=conn.cursor(cursor=pymysql.cursore.DictCursor) res=cur.execute('select*from dep;') print(res) print(cur.fetchone()) print(cur.fetchone()) print(cur.fetchamany(3)) print(cur.fetchall()) cur.scroll(6,mode='absolute')#相对绝对位置移动 print(cur.fetchone()) cur.scroll(2,mode='absolute')相对绝对位置移动 print(cur.fetchone()) print(cur.frtchone()) cur.scroll(1,mode='relative')相对当前位置移动 print(cur.fetchone()) cur.scroll(1,mode='relative') print(cur.fetchone()) print(cur.fetchall()) cur.scroll(-1,mode='relative') print(cur.fetchone()) cur.execute('insert into dep(name)values('ee');') print.commit() cur,close() conn,close()