2017-10-20 64 views
0

我使用这下面的代码来更新我的表中的记录,但它不工作,并没有更新我的表Python的MYSQL更新

conn = mysql.connector.connect(host='localhost', 
            database='rps', 
            user='root', 
            password='') 
    cur = conn.cursor() 
    cur.execute("""UPDATE players SET score=%s WHERE chat_id =%s""", (int(self.p1.score), str(self.p1.chat__id))) 
    cur.execute("""UPDATE players SET score=%s WHERE chat_id =%s""", (int(self.p2.score), str(self.p2.chat__id))) 
    conn.commit() 
    cur.close() 
    conn.close() 

这是完全正确的,但我不知道如何解决这个问题 你能帮我解决它吗? 感谢

+0

没有人不知道答案? – mahdi

回答

0

您可以设置的try/catch在你的查询执行:

try: 
    cursor.execute(some_statement) 
except MySQLdb.IntegrityError, e: 
    # handle a specific error condition 
except MySQLdb.Error, e: 
    # handle a generic error condition 
except MySQLdb.Warning, e: 
    # handle warnings, if the cursor you're using raises them 

如果你没有发现任何异常,你应该检查你的程序逻辑。