Post Page Advertisement [Top]



Click here to send WhatsApp On Unsaved Mobile Numbers For Free

Not all parameters were used in the SQL statement (mysql.connector.errors.ProgrammingError with Python)
mysql.connector.errors.ProgrammingError


Not all parameters were used in the SQL statement

Hi, friends you will get an error "mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement" when you pass more than one arguments through execute(arg1, arg2, ...) function.

Not all parameters were used in the SQL statement (mysql.connector.errors.ProgrammingError with Python)

Error:
Traceback (most recent call last):
  File "d:/-----------/-----------/-------------/-----------/test.py", line 18, in <module>
    cursor.execute(sqlQuery, queryMatch)
  File "C:\----------\--------\------------\-------------\-------------\Python\Python38-32\lib\site-packages\mysql\connector\cursor.py", line 560, in execute
mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement

Not all parameters were used in the SQL statement (mysql.connector.errors.ProgrammingError with Python)

To solve this error there are two solutions. The both solutions are given below.
-
-
Solution 1:

Pass prepared=True as an argument in the cursor() function as like cursor = con.cursor(prepared=True)

See the full program or code below:
Not all parameters were used in the SQL statement (mysql.connector.errors.ProgrammingError with Python)
***
import mysql.connector as mysql

con = mysql.connect(
    host = 'localhost',
    user = 'root',
    passwd = 'rootPassword',
    database = 'dbName',
    auth_plugin = 'mysql_native_password',
    port = 3306
)

cursor = con.cursor(prepared=True)

sqlQuery = '''SELECT * FROM users WHERE username = ? AND password = ?'''

queryMatch = ['rohit', 'rohit']

cursor.execute(sqlQuery, queryMatch)

records = cursor.fetchall()

for record in records:
    print(record)

print('Connected successfully...')

con.close()
print('Connection closed...')
-
-
Solution 2:

Use %s at the place of ? in the SQL query.
sqlQuery = '''SELECT * FROM users WHERE username = %S AND password = %S'''
See full program or coding below:
Not all parameters were used in the SQL statement (mysql.connector.errors.ProgrammingError with Python)
***
import mysql.connector as mysql

con = mysql.connect(
    host = 'localhost',
    user = 'root',
    passwd = 'rootPassword',
    database = 'dbName',
    auth_plugin = 'mysql_native_password',
    port = 3306
)

cursor = con.cursor()

sqlQuery = '''SELECT * FROM users WHERE username = %s AND password = %s'''

queryMatch = ['rohit', 'rohit']

cursor.execute(sqlQuery, queryMatch)

records = cursor.fetchall()

for record in records:
    print(record)

print('Connected successfully...')

con.close()
print('Connection closed...')
-
-
---
I hope you likable this nice post. Do not forget to share it together with your friends, the Sharing Button is below the post. Apart from this, if there's any downside within the intermediate, don't hesitate to request the Comment Box. we are going to be happy to help you.

I will continue to write more and more on this blog, so do not forget to make our blog BlogLearner as a bookmark (Ctrl + D) on your mobile or computer and subscribe to us to get all the posts in your email. Do not forget to share these posts, if you like it. You can facilitate us reach additional individuals by sharing it on social networking sites like Facebook or Twitter.

thankyou-rrkksinha-bloglearner, thanks, thank you, thanku
mysql.connector.errors.ProgrammingError with Python
#rrkksinha #bloglearner #disable_automatic_windows_update

No comments:

Post a Comment

Bottom Ad [Post Page]

rrkksinha.