Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
sudeepaviraj committed Jun 22, 2023
1 parent 6a19217 commit bb88387
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import json

import mysql.connector

def Query(sql):
connection = mysql.connector.connect(
host="YOUR DATABASE HOST",
port="YOUR DATABASE PORT",
user="YOUR DATABASE HOST",
password="YOUR DATABASE PASSWORD",
database="YOUR DATABASE"
)
cursor = connection.cursor()

try:
cursor.execute(sql)
connection.commit()
connection.close()
return "done"
except Exception as e:
raise SyntaxError(e)


def SelectQuery(sql) -> list:
connection = mysql.connector.connect(
host="YOUR DATABASE HOST",
port="YOUR DATABASE PORT",
user="YOUR DATABASE HOST",
password="YOUR DATABASE PASSWORD",
database="YOUR DATABASE"
)
dataset = []
try:
curser = connection.cursor()
curser.execute(sql)
responses = curser.fetchall()
try:
for response in responses:
dataset.append({"id": response[0], "name": response[1].decode("utf-8")})
except Exception as e:
for response in responses:
dataset.append({"id": response[0], "name": response[1]})
connection.close()
return dataset
except Exception as e:
raise SyntaxError(e)

0 comments on commit bb88387

Please sign in to comment.