-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.py
40 lines (29 loc) · 846 Bytes
/
view.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
import mysql.connector
# Configure the database connection
config = {
"user": "root",
"password": "q1w2E#R$",
"host": "localhost",
"database": "solana_nft"
}
# Establish the connection
connection = mysql.connector.connect(**config)
if connection.is_connected():
print("Connected to MySQL database")
cursor = connection.cursor()
# Perform database operations here
sql = "SELECT * FROM nft_events ORDER BY timestamp ASC LIMIT 100"
cursor.execute(sql)
# Fetch all rows
rows = cursor.fetchall()
for row in rows:
print(row)
sql = "SELECT COUNT(*) FROM nft_events"
cursor.execute(sql)
# Fetch all rows
count = cursor.fetchone()[0]
print("COUNT; ", count)
cursor.close()
# Close the connection when done
connection.close()
print("Connection closed")