Python MYSQL update statement

前端 未结 5 1616
时光取名叫无心
时光取名叫无心 2020-11-27 02:27

I\'m trying to get this Python MYSQL update statement correct(With Variables):

cursor.execute (\"UPDATE tblTableName SET Year=%s\" % Year \", Month=%s\" % Mo         


        
5条回答
  •  再見小時候
    2020-11-27 03:14

    @Esteban Küber is absolutely right.

    Maybe one additional hint for bloody beginners like me. If you speciify the variables with %s, you have to follow this principle for EVERY input value, which means for the SET-variables as well as for the WHERE-variables.

    Otherwise, you will have to face a termination message like 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s WHERE'

提交回复
热议问题