I want to make a python script that consistently checks the Mysql database and prints out new updated records every few seconds.
import time
sql_conn = connectSQLServer('ODBC Driver 13 for SQL Server', 'D\SQLEXPRESS', 'display')
mycursor = sql_conn.cursor()
a = 0
while True:
try:
time.sleep(1)
a=a+1
print(a)
sql = "SELECT id, val FROM dbo.LiveStatsFromSQLServer"
mycursor.execute(sql)
myresult = mycursor.fetchall()
for x in myresult:
print(x)
except Exception as error:
print("Nothing in database\n")
print(error)
sql_conn.commit()
Expected output: The columns are (id, value)
1second
(1625, 3)
(1626, 0)
(1627, 10)
2second
(1625, 3)
(1626, 0)
(1627, 10)
3second
(1625, 3)
(1626, 0)
(1627, 10)
(1628,20)