pymysql的使用_sql

pymysql的使用_mysql_02



pymysql的使用_mysql_03






config = {

'host':'127.0.0.1', #主机号

'port':3306, #端口号

'user':'root', #数据库用户名

'passwd':'root', #数据库密码

'charset':'utf8mb4', #utf-8编码,显示中文不乱吗

'cursorclass':pymysql.cursors.DictCursor #查询返回变字典模式

}

conn = pymysql.connect(**config) #连接数据库


cursor = conn.cursor() #获取游标对象,用于执行查询和获取结果


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('登陆失败!')