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()
    
  • 相关阅读:
    Keras如何构造简单的CNN网络
    到底该如何入门Keras、Theano呢?(浅谈)
    PyCharm使用技巧记录(一)如何查看变量
    使用 环境变量 来配置批量配置apache
    QT静态链接
    NTP服务器
    debian添加sudo
    龙芯8089_D安装debian 8 iessie
    verilog 双向IO实现
    FPGA入门学习第一课:二分频器
  • 原文地址:https://www.cnblogs.com/linqiaobao/p/12842910.html
Copyright © 2011-2022 走看看