zoukankan      html  css  js  c++  java
  • day48 work

    1 navicat自己玩一玩

    2 练习题一定要搞懂 照着我的思路一遍遍的看敲

    3 熟悉pymysql的使用

    4 sql注入产生的原因和解决方法 了解

    5 思考:如何结合mysql实现用户的注册和登录功能?

    import pymysql
    
    #链接数据库
    conn=pymysql.connect(
        host='127.0.0.1',
        port=3306,
        user='root',
        password='123456',
        db='day48',
        charset='utf8'
    )
    #获取游标
    cursor=conn.cursor(cursor=pymysql.cursors.DictCursor)
    
    #注册功能
    def register():
        while True:
            user=input('your name:').strip()
            pwd=input('your pwd>>:').strip()
            re_pwd=input('your pwd>>:').strip()
            if pwd == re_pwd:
                sql='insert into userinfo values(%s,%s);'
                rows=cursor.execute(sql,(user,pwd))
                # 提交
                conn.commit()
                #验证是否注册成功
                sql = 'select * from userinfo where name = %s and pwd =%s;'
                rows = cursor.execute(sql, (user, pwd))
                if rows:
                    print('注册成功')
                    break
                else:
                    print('注册失败')
                # 关闭游标
                cursor.close()
    
                # 关闭连接
                conn.close()
            else:
                print('两次密码输入不一致')
    
    #登录功能
    def login():
        while True:
            user=input('your name>>:').strip()
            pwd=input('your pwd>>:').strip()
            sql='select * from userinfo where name = %s and pwd =%s;'
            rows=cursor.execute(sql,(user,pwd))
            if rows:
                print('登录成功')
                break
            else:
                print('登录失败')
            # 关闭游标
            cursor.close()
    
            # 关闭连接
            conn.close()
    
    
    func_dic={
        '1':register,
        '2':login,
    }
    
    def run():
        while True:
            print('''
            1 注册
            2 登录
            ''')
            choice=input('>>:').strip()
            if choice == 'q':
                break
            elif choice not in func_dic:
                print('没有该编号')
                continue
            func_dic.get(choice)()
    
    
    run()
    
  • 相关阅读:
    vue的工作机制
    koa中的执行顺序
    vue项目中的keep-alive缓存
    vue项目中组件的重新初始化
    常用的JS代码块收集
    每个程序员都必须遵守的编程原则--转了
    自己写操作系统 2
    自己写操作系统 1
    【转】Hadoop安装教程_单机/伪分布式配置_Hadoop2.6.0/Ubuntu14.04
    ubuntu14.04LTS openssh-server 手动安装配置步骤
  • 原文地址:https://www.cnblogs.com/linqiaobao/p/12842910.html
Copyright © 2011-2022 走看看