import pymysql
class Mydb:
config={
"host":"localhost",
"user":"root",
"password":"2086",
"db":"music",
"charset":"utf8"
}
def __init__(self):
self.connection=pymysql.connect(**Mydb.config)
self.cursor=self.connection.cursor()
def close(self):
if self.cursor:
self.cursor.close()
if self.connection:
self.connection.close()
def exeDML(self,sql,*args):
try:
count=self.cursor.execute(sql,args)
self.connection.commit()
return count
except Exception as e:
print(e)
if self.connection:
self.connection.rollback()
finally:
self.close()
def query_one(self,sql,*args):
try:
self.cursor.execute(sql,args)
self.cursor.fetchone()
except Exception as e:
print(e)
finally:
self.close()
def query_all(self,sql,*args):
try:
self.cursor.execute(sql,args)
return self.cursor.fetchall()
except Exception as e:
print(e)
finally:
self.close()
from DBUtill import Mydb
class MyService:
def login(self,uname,password):
sql="select * from music_project where uname=%s and password=%s"
user = Mydb().query_one(sql,uname,password)
if user:
return True
else:
return False
from MyService import MyService
if __name__ == "__main__":
uname = input("enter user name:")
password = input("enter password:")
myservice = MyService()
if myservice.login(uname,password):
print("success login")
else:
print("fail login")


老师不知道哪里出问题,对的用户名和密码但是登录失败