Not all parameters were used in the SQL statement (Python, MySQL)

后端 未结 3 1530
一个人的身影
一个人的身影 2020-11-29 06:03

I get an error on the following Python code:

import mysql.connector
cnx = mysql.connector.connect(user=\'root\', password=\'\',
                          hos         


        
3条回答
  •  一个人的身影
    2020-11-29 06:49

    The parameter marker is %s not %d.

    add_user = """INSERT INTO DB.tbluser 
                  (username, department, startyear, currentpos, link) 
                  VALUES (%s, %s, %s, %s, %s)"""
    

    Note that the parameter markers used by mysql.connector may look the same as the %s used in Python string formatting but the relationship is only coincidental. Some database adapters like oursql and sqlite3 use ? as the parameter marker instead of %s.

提交回复
热议问题