铁路校友-我拆过的坑cycx

主页:www.j6f.cn知识星球,快手号、抖音号、视频号、微信公众号、百家号、个人博客网站,同名。

pymysql基本用法

import pymysql


user = input('username:')

pwd  = input('password:')


conn = pymysql.connect(host='localhost',user='root',password='',database='db1')

cursor = conn.cursor()

sql = "select * from userinfo where user=%s and password=%s"

# sql = "select * from userinfo where user=%(u)s and password=%(p)s"

cursor.execute(sql,[user,pwd])

# cursor.execute(sql,{'u':user,'p':pwd})

ret = cursor.fetchone()


cursor.close()

conn.close()


if ret:

    print('登陆成功!')

else:

    print('登陆失败!')


Powered By Z-BlogPHP 1.7.3

Copyright Your WebSite.Some Rights Reserved.