Not all parameters were used in the SQL statement (Python, MySQL)
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
.
Not all parameters were used in the SQL statement Python - MySql
The second argument to execute()
should be a sequence of values, one for each placeholder token %s
in the query.
You did pass a sequence, but not in the way you intended. Strings are sequences, so you actually passed a sequence of four values - T, E, S, T
, which is too many values, because the query only has one placeholder token.
Pass the string as a one-element tuple, like so:
args = ("TEST",)
sql = """SELECT * FROM musics WHERE Id = %s"""
dbc.execute(sql, args)
Related Topics
How to Break a Long Line to Multiple Lines in Python
How to Catch a Numpy Warning Like It's an Exception (Not Just for Testing)
Nonlocal Keyword in Python 2.X
How to Create an Encrypted Zip File
Numpy.Unique with Order Preserved
Wrapping a C Library in Python: C, Cython or Ctypes
Check If a File Is Open in Python
How to Set a Default Parameter Equal to Another Parameter Value
Why Doesn't Os.Path.Join() Work in This Case
A Tool to Convert Matlab Code to Python
Accessing Object Memory Address
Using Requests with Tls Doesn't Give Sni Support
How to Set Folder Permissions in Windows
Multiprocessing.Pool: What's the Difference Between Map_Async and Imap