1、sql传递参数:
cursor.execute(str_sql, m)
2、中文字段显示乱码:连接数据库时指定编码:charset='GBK'
with pymssql.connect(self.host, self.user, self.password, self.dataBaseName, timeout=10, charset='GBK') as conn:
with conn.cursor(as_dict=True) as cursor: # 数据存放到元组列表中
# sqlStr = executeScriptsFromFile("./res/customRef.sql")
str_sql = "SELECT * FROM A WHERE id = (%s)"
cursor.execute(str_sql, m) # m为参数,对应上面的id
for row in cursor:
bodyList.append(row)