Answer the question
In order to leave comments, you need to log in
Why isn't it returning new data from the database?
Hello dear experts.
I can not figure out why my code does not return new data from the database,
here is the code:
import pymysql
from pymysql.cursors import DictCursor
mysql_connections = None
def connection_to_mysql():
global mysql_connections
if mysql_connections == None or not mysql_connections.open:
try:
mysql_connections = pymysql.connect(host = db_host, user = db_username, password = db_password, db = db_dbname, charset = 'utf8mb4', cursorclass = DictCursor)
except pymysql.Error as err:
print('Mysql error: '+str(err.args[1]))
return False
return True
while True:
rows = []
if connection_to_mysql():
try:
with mysql_connections.cursor() as cursor:
sql = 'SELECT * FROM `test` WHERE `id` > 14 ORDER BY `id` ASC'
cursor.execute(sql)
rows = cursor.fetchall()
print(str(rows))
except pymysql.Error as err:
print('Mysql error: '+str(err.args[1]))
break
time.sleep(5)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question