我想创建一个 SQL 查询字符串并从 python 执行它import mysql.connectorfrom mysql.connector import Errorclient = mysql.connector.connect(host=sql_host, port=sql_port, database=sql_db, user=os.environ['SQLUSER'], passwd=os.environ['SQLPASS'] )try: a = "val1" b = "val2" cursor = client.cursor() query = "insert into mytable values ('{}', '{}')".format(a,b) print(query) cursor.execute(query)except Error as e: print(e)这不会给我错误,但同时,表中没有插入任何内容。我认为那是因为创建的查询字符串看起来像"insert into mytable values (\\'val1\\', \\'val2\\')"我什至尝试过,.replace('\\','')但我无法\\从查询字符串中删除 s。我做错了什么?
添加回答
举报
0/150
提交
取消