moved scripts to database scripts
This commit is contained in:
34
py_app/app/db_create_scripts/query.py
Normal file
34
py_app/app/db_create_scripts/query.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import mariadb
|
||||
|
||||
# Database connection credentials
|
||||
db_config = {
|
||||
"user": "trasabilitate",
|
||||
"password": "Initial01!",
|
||||
"host": "localhost",
|
||||
"database": "trasabilitate_database"
|
||||
}
|
||||
|
||||
try:
|
||||
# Connect to the database
|
||||
conn = mariadb.connect(**db_config)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Query to fetch all records from the scan1 table
|
||||
query = "SELECT * FROM scan1_orders ORDER BY Id DESC LIMIT 15"
|
||||
cursor.execute(query)
|
||||
|
||||
# Fetch and print the results
|
||||
rows = cursor.fetchall()
|
||||
if rows:
|
||||
print("Records in the 'scan1_orders' table:")
|
||||
for row in rows:
|
||||
print(row)
|
||||
else:
|
||||
print("No records found in the 'scan1_orders' table.")
|
||||
|
||||
# Close the connection
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
except mariadb.Error as e:
|
||||
print(f"Error connecting to the database: {e}")
|
||||
Reference in New Issue
Block a user