-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpushdb.py
50 lines (39 loc) · 1.33 KB
/
pushdb.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import mysql.connector
# Replace these with your actual MySQL server details
db_config = {
'host': '34.194.132.130',
'user': 'test',
'password': 'test123',
'database': 'touch_and_go_test',
}
try:
connection = mysql.connector.connect(**db_config)
cursor = connection.cursor()
# Perform database operations here
# Example: cursor.execute("INSERT INTO your_table (column1, column2) VALUES (%s, %s)", (value1, value2))
# Example: cursor.execute("SELECT * FROM your_table")
# Don't forget to commit changes if necessary: connection.commit()
# Execute your SELECT query
#query = "SELECT * FROM student"
#cursor.execute(query)
# Fetch all the rows
#rows = cursor.fetchall()
# Print the results to the console
#for row in rows:
# print(row)
#id first name lastname email password
insert_query = "INSERT INTO student (userId, firstName, lastName) VALUES (%s, %s, %s)"
print("Enter ID: ")
index = input()
print("Enter your first name: ")
fname = input()
print("Enter your last name: ")
lname = input()
data = (index, fname, lname)
cursor.execute(insert_query, data)
connection.commit()
except mysql.connector.Error as err:
print(f"Error: {err}")
finally:
if 'connection' in locals():
connection.close()