会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132358个问题
Python 全系列/第五阶段:数据库编程/mysql的使用 76楼
Python 全系列/第五阶段:数据库编程/项目-音乐播放器-旧 77楼

image.png

Python 全系列/第五阶段:数据库编程/MySQL数据库的使用 78楼
Python 全系列/第五阶段:数据库编程/mysql的使用 79楼
Python 全系列/第五阶段:数据库编程/mysql介绍与环境安装 82楼
Python 全系列/第五阶段:数据库编程/mysql的使用 83楼

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")

image.pngimage.png


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

Python 全系列/第五阶段:数据库编程/项目-音乐播放器-旧 84楼
Python 全系列/第五阶段:数据库编程/mysql的使用 85楼
Python 全系列/第五阶段:数据库编程/MySQL数据库的使用 88楼
Python 全系列/第五阶段:数据库编程/mysql的使用 89楼
Python 全系列/第五阶段:数据库编程/mysql的使用 90楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637