-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_database.py
More file actions
39 lines (27 loc) · 874 Bytes
/
Copy pathsetup_database.py
File metadata and controls
39 lines (27 loc) · 874 Bytes
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
37
38
39
import mysql.connector
# Mengatur koneksi ke database MySQL
db = mysql.connector.connect(
host="localhost",
user="imam",
password="12345"
)
# Membuat database jika belum ada
def create_database():
cursor = db.cursor()
cursor.execute("CREATE DATABASE IF NOT EXISTS uas_km")
print("Database created successfully!")
# Membuat tabel untuk menyimpan pengetahuan eksplisit
def create_table():
cursor = db.cursor()
cursor.execute("USE uas_km")
cursor.execute(
"CREATE TABLE IF NOT EXISTS extracted_knowledge (id INT AUTO_INCREMENT PRIMARY KEY, category VARCHAR(255), sentence TEXT, accuracy FLOAT)")
print("Table created successfully!")
# Menutup koneksi database
def close_connection():
db.close()
# Menjalankan fungsi setup
if __name__ == "__main__":
create_database()
create_table()
close_connection()