O
O
Onotolius2021-10-10 21:03:36
MySQL
Onotolius, 2021-10-10 21:03:36

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)


The code every 5 seconds queries the table and pulls everything out of there.
For example, there are 27 rows in the table, I run the code, it returns all 27 rows as expected, every 5 seconds. one and the same in essence.
Then I add one or more rows to the table. But the code still returns 27 rows as before.
What's the matter, who knows?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question