首页 > 解决方案 > 循环中的 Python mysql-connector SELECT 返回过时的结果

问题描述

我正在使用 mysql-connectorSELECT在 while 循环中运行查询以查找新作业。

import mysql.connector

while True:
        sql.execute("select id, mailing_list, account_list, template from dom_campaigns where status = 0")
        campaigns = sql.fetchall()

如果我在表中插入一行并启动脚本,它会处理它。但是,如果我启动脚本,然后在脚本运行时插入一行,它永远不会因为fetchall(). 我必须停止/启动脚本才能显示出来。

为什么要这样做,如果在脚本运行时插入行,我怎样才能让它获取行?

标签: mysqlpython-3.xloopsmysql-connector

解决方案


推荐阅读