会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132654个问题

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 全系列/第五阶段:数据库编程/项目-音乐播放器-旧 2823楼
2019人工智能(隐藏)/第十阶段:深度学习原理架构与实战/Tensorflow使用优化器以及模型的存储和加载 2824楼
Python 全系列/第十四阶段:Python 爬虫开发/scrapy框架使用(旧) 2826楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 2829楼
Python 全系列/第十四阶段:Python 爬虫开发/移动端爬虫 2832楼
Python 全系列/第四阶段:函数式编程和核心特性/函数式编程核心(高阶函数、闭包等) 2835楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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