在给定的代码中,有一个select方法用于从数据库中查询数据。但是,SQL语句的语法是不正确的。以下是修正后的代码:

def select(self):
    db = pymysql.connect(host='localhost', user='root', password='111111', port=3306, db='student', charset='utf8')
    self.cursor = db.cursor()
    sql = f"SELECT * FROM pigherd WHERE herdid='{self.herdid_t}' OR herdname='{self.herdname_t}' OR creattime='{self.creattime_t}'"
    self.cursor.execute(sql)
    result = self.cursor.fetchone()
    print(result)
    db.close()

在修正后的代码中,我使用了f-string来动态构建SQL查询语句。这样可以保证输入的值被正确地包含在查询语句中。同时,我还添加了一些缺失的逻辑操作符(例如OR)来组合查询条件。请根据您的实际需求进行修改


原文地址: https://www.cveoy.top/t/topic/h4lx 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录