TypeError: Not All Arguments Converted During String Formatting in Parameterized SQL Queries
Your code for a parameterized SQL query throws the error "TypeError: not all arguments converted during string formatting" because you're trying to directly substitute a string into the query. This approach doesn't work because it expects a list of arguments to be converted into the query.
To rectify this issue, rather than using:
cur.execute( "SELECT * FROM records WHERE email LIKE '%s'", search )
modify your code to:
cur.execute( "SELECT * FROM records WHERE email LIKE %s", [search] )
As per the MySQLdb documentation, the second parameter of execute() represents a list of objects to be converted, allowing for an arbitrary number of objects in a single query. In your case, despite having only one object, it still needs to be an iterable.
The above is the detailed content of How to Fix 'TypeError: Not All Arguments Converted' in Parameterized MySQL Queries?. For more information, please follow other related articles on the PHP Chinese website!