我的功能有问题:
def dataf (p,k):
try:
connection = mysql.connector.connect(host='host',
database='products',
user='user',
password='pwd')
sql_select_Query = "select a from table where b LIKE %s AND c LIKE %s"
cursor = connection.cursor()
cursor.execute(sql_select_Query, ('%' + p+ '%',), ('%' + k + '%',))
records = cursor.fetchall()
return records
except Error as e:
print("Error reading data from MySQL table", e)
finally:
if (connection.is_connected()):
connection.close()
cursor.close()
当我仅使用第一个占位符执行此功能时,一切正常。使用第二个占位符,我得到 TypeError: NoneType
例如,使用第二个占位符,我想检查 ca 列中的值是否类似于 = 0,5 kg。当我编写没有第二个占位符的查询并直接插入值时,一切正常:
sql_select_Query = "select a from table where b LIKE %s AND c LIKE '0,5 kg'"
我究竟做错了什么?