I'm making a program in python that connects to a mysql database and can access it and manipulate it. I am using PyMySQL in order to do this however I am stumped by this error that keeps occuring in my program. Here is the error:
cursor.execute("SELECT * FROM Bookings WHERE ? = ?", record, recordtype)
TypeError: execute() takes from 2 to 3 positional arguments but 4 were given
def findbooking():
recordtype = input("Which field do you want to search?: ")
record = input("Enter what you want to search: ")
findbookingsql(record, recordtype)
def findbookingsql(record, recordtype): #Connect to Database and find record specified
conn = sql.connect(server,user, password,database)
cursor = conn.cursor()
cursor.execute("SELECT * FROM Bookings WHERE ? = ?",recordtype,record)
row = cursor.fetchone()
conn.close()
return row
Encapsulate the parameters in a tuple, rather than stand alone arguments:
cursor.execute("SELECT * FROM Bookings WHERE ? = ?", (record, recordtype))