0

Am having problems with MySql not recognizing this syntax.

I think the issue is in the the exceute statement. I was using their previous method https://dev.mysql.com/doc/connector-python/en/connector-python-example-cursor-transaction.html

def insertPS3(name,gamedb):
    mycursor = gamedb.cursor()
    mycursor.execute("""INSERT INTO ps3 (name) VALUES (%s,)""" % (name,))
    gamedb.commit()

Edit

'%s' is the fix

alpha245
  • 1
  • 1
  • 2

1 Answers1

3

Instead of formatting the SQL statement using python string formatting you should let the cursor handle it for you. Passing a tuple of params as the second argument to execute (the same length as the number of %ss in the statement) will allow the cursor to perform the correct string formatting

mycursor.execute("INSERT INTO ps3 (name) VALUES (%s)", (name,))
Iain Shelvington
  • 31,030
  • 3
  • 31
  • 50