0
import mysql.connector
conn=mysql.connector.connect(user="root",password="",host="localhost",port="3306",database="ddp")
cur=conn.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS Employer( CompanyID varchar(5) PRIMARY KEY, CompanyName varchar(50) NOT NULL, City varchar(15))')
#cur.execute("INSERT INTO Employer(CompanyID,CompanyName, City) VALUES ('a123','TATA','MUMBAI')")
id1="a123"
cur.execute("SELECT * FROM Employer WHERE CompanyID = %s",(id1))
print(cur.fetchall())
#print(cur.description)
conn.commit()
cur.close()
conn.close()

This my code above, I am trying the select statement with the value given through the variable id1, but it is not working and gives the following error

Traceback (most recent call last):
  File "C:/Users/DELL/Desktop/PYTHON/module2/check.py", line 7, in <module>
    cur.execute("SELECT * FROM Employer WHERE CompanyID = %s",(id1))
  File "F:\PYTHON_3.5\lib\site-packages\mysql\connector\cursor_cext.py", line 246, in execute
    prepared = self._cnx.prepare_for_mysql(params)
  File "F:\PYTHON_3.5\lib\site-packages\mysql\connector\connection_cext.py", line 520, in prepare_for_mysql
    raise ValueError("Could not process parameters")
ValueError: Could not process parameters
SATYAM SAREEN
  • 41
  • 2
  • 8
  • `(id1)` is not a tuple of one element, `id1`, it's just `id1` itself. Tuples are made by commas, not parens; the parens are just for disambiguation. This is especially confusing if `id1` is a string, because a string is a sequence of its characters, so you're actually passing a sequence of 4 arguments here. [The docs](https://www.python.org/dev/peps/pep-0249/#id15) explain this, but the linked dups should also explain it. If it isn't clear, let me know and we can probably find better ones and/or improve the explanation. – abarnert Jul 07 '18 at 19:51
  • I understood from the duplicate question, thanx for the answer – SATYAM SAREEN Jul 07 '18 at 20:25
  • 1
    Great! By the way, I know that it's hard to search for existing answers on Stack Overflow, and the list of possible duplicates it shows you when you ask is usually useless. A trick that may help is to search DuckDuckGo, Google, whatever with `site:stackoverflow.com [python] parameterized query not working` instead of searching the Python tag on Stack Overflow itself for `parameterized query not working`. – abarnert Jul 07 '18 at 20:36

0 Answers0