-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql.py
28 lines (22 loc) · 928 Bytes
/
sql.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from pymysql import *
def insert_code(user_number, user_name, password, entering_date):
"""
Function it enter user to sql table
:param user_username: Username to enter
:param user_name: username to enter
:param password to enter
:return:entering the user name to the table
"""
connection = None
try:
if connection is None:
connection = connect(host='127.0.0.1', user='root', password=None, db='exercise_diceware',
cursorclass=cursors.DictCursor)
query = "INSERT INTO accounts(user_number,user_name, password,entering_date) VALUES (%d,'%s','%s','%s')" % (
user_number, user_name, password, entering_date)
connection.cursor().execute(query)
connection.commit()
except MySQLError:
print("Database error")
else:
connection.close()