Spaces:
Running
Running
import mysql.connector | |
from mysql.connector import Error | |
import config | |
try: | |
conn = mysql.connector.connect(**config.db_config) | |
if conn.is_connected(): | |
print("✅OK!") | |
cursor = conn.cursor() | |
cursor.execute("SELECT id, filename, sentence FROM tts_data ORDER BY id DESC LIMIT 5") | |
records = cursor.fetchall() | |
print("🟢Last 5 records:") | |
for record in records: | |
print(record) | |
except Error as e: | |
print("❌ error:", e) | |
finally: | |
if 'cursor' in locals(): | |
cursor.close() | |
if 'conn' in locals() and conn.is_connected(): | |
conn.close() | |
print("⛔️Closed.") | |