예제 #1
0
def insert_data(porn_file, unporn_file):
    mysql_helper = MysqlHelper('193.168.15.136', 'test', 'test', 'p**n',
                               'utf8')
    with open(porn_file, 'r', encoding='utf-8', errors='ignore') as fporn_read:
        for line in fporn_read:
            sql_query = "select * from p**n where Content= %s"
            param_query = line.rstrip()
            result = mysql_helper.find(sql_query, param_query)
            if result == 0:
                sql_insert = 'insert into p**n(ID,Content) values (%s,%s)'
                md5 = hashlib.md5()
                md5.update(line.rstrip().encode(encoding='utf-8'))
                param_insert = md5.hexdigest(), line.rstrip()
                mysql_helper.cud(sql_insert, param_insert)
    with open(unporn_file, 'r', encoding='utf-8') as funporn_read:
        for line in funporn_read:
            sql_query = "select * from unporn where Content= %s"
            param_query = line.rstrip()
            result = mysql_helper.find(sql_query, param_query)
            if result == 0:
                sql_insert = 'insert into unporn(ID,Content) values (%s,%s)'
                md5 = hashlib.md5()
                md5.update(line.rstrip().encode(encoding='utf-8'))
                param_insert = md5.hexdigest(), line.rstrip()
                mysql_helper.cud(sql_insert, param_insert)
예제 #2
0
class CheckLogin():
    def __init__(self):
        self.mysql_helper = MysqlHelper(host="localhost",
                                        user="******",
                                        passwd="123456",
                                        port=3306,
                                        db='python')

    def get_message(self):
        self.username = input("用户名:")
        self.password = input("密码:")

        hash_password = hashlib.sha1()
        hash_password.update(self.password.encode("utf-8"))
        self.hash_password = hash_password.hexdigest()

    def judge_user(self):
        sql = "select passwd from user_passwd where username=%s"
        params = [self.username]
        self.result = self.mysql_helper.find_get(sql, params)

    def login(self):

        self.get_message()
        #user_passwd
        self.judge_user()
        if self.result == ():
            print("\n用户不存在,请注册")
            register = input("是否注册[Y/N]:")
            if register.lower() == "y":
                self.register()
            else:
                print("成功退出")
        else:
            if self.result[0][0] == self.hash_password:
                print("\n*******登录成功********")
            else:
                print("\n密码错误")

    def register(self):
        self.get_message()
        self.judge_user()
        if self.result == ():
            sql = "insert into user_passwd values(0,%s,%s);"
            params = [self.username, self.hash_password]
            self.mysql_helper.cud(sql, params)
        else:
            print("用户已存在,请登录")
            login = input("是否登录[Y/N]:")
            if login.lower() == "y":
                self.login()
            else:
                print("成功退出")
예제 #3
0
# coding:utf-8

from MysqlHelper import *

params = ["fedddr", "2"]
sql = "UPDATE xiaoliu SET name=%s WHERE id<%s"

mysql_helper = MysqlHelper(host="localhost",
                           user="******",
                           passwd="123456",
                           port=3306,
                           db='python')

# mysqls.cud(sql,params)
# sql = "select *from xiaoliu;"
# params=[]
# print(mysqls.find_get(sql,params))
mysql_helper.cud("update xiaoliu set age=3;")

mysql_helper.find_get("select *from xiaoliu;")
mysql_helper.show_result()
예제 #4
0
#encoding=utf-8

from  MysqlHelper import *

id1=input('请输入学号')
name =input('请输入名字')

sql='update tb_info set infoname=%s where id=%s'
params=[name,int(id1)]

sqlhelper=MysqlHelper('localhost',3306,'pymysql','root','kcy000')
sqlhelper.cud(sql,params)
query='select * from tb_info'
param=[]
print(sqlhelper.all(query,param))