[英]python sql escape forward slash not working
我正在嘗試執行一條sql語句,該語句應將某些數據添加到數據庫中,如下所示:
cursor.execute("INSERT INTO Actors (imdbPageId, fullName) VALUES (%s, %s)" % ( db.escape_string(self.imdbID), self.name))
我也嘗試過:
cursor.execute("INSERT INTO Actors (imdbPageId, fullName) VALUES (%s, %s)" % ( self.imdbID, self.name))
但是無論是否使用escape_string
我都會不斷收到此錯誤。 見下文:
MySQLdb._exceptions.ProgrammingError:(1064,“您的SQL語法有錯誤;請在第1行的'/ name / nm0991810,Mahershala Ali)附近,查看與MySQL服務器版本相對應的手冊以使用正確的語法” )
我很確定它與正斜杠有關,但我無法使其正常工作。 我該如何解決這個問題?
如果需要更多信息,請告訴我!
改為這樣做:
query = "INSERT INTO Actors (imdbPageId, fullName) VALUES (%s, %s)"
cursor.execute(query, (self.imdbID, self.name))
如果我沒有記錯的話, mysqldb
會為您解決這個問題。
否則,您可以執行以下操作:
cursor.execute(query, (db.escape_string(self.imdbID), self.name))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.