我拆过的坑cycx

查询一下!

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.