-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.py
36 lines (31 loc) · 1.05 KB
/
admin.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
29
30
31
32
33
34
35
36
import mysql.connector
from mysql.connector import Error
from dotenv import load_dotenv
import os
load_dotenv()
def admin(name, username, password):
try:
connection = mysql.connector.connect(
host=os.getenv('MYSQL_HOST'),
database=os.getenv('MYSQL_DB'),
user=os.getenv('MYSQL_USER'),
password=os.getenv('MYSQL_PASSWORD')
)
if connection.is_connected():
cursor = connection.cursor()
query = "INSERT INTO admin (name, username, password) VALUES (%s, %s, %s)"
cursor.execute(query, (name, username, password))
connection.commit()
print("Admin data inserted successfully")
except Error as e:
print(f"Error: {e}")
finally:
if connection.is_connected():
cursor.close()
connection.close()
print("MySQL connection is closed")
if __name__ == "__main__":
name = "Admin BSI Bengkalis"
username = "admin-bsi-bks"
password = "admin@bsi-bks"
admin(name, username, password)