File size: 655 Bytes
ac40033
 
2ff3847
ac40033
 
2ff3847
ac40033
 
 
 
1ef4e10
 
 
 
 
 
ac40033
 
 
 
 
 
 
 
 
1ef4e10
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
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.")