I created a query in MySQL workbench to test out using MySQL in python, it runs fine in workbench, but when I run it in python, it tells me the part after the WHERE is invalid syntax
I have looked around for this issue and cannot find it, python MySQL works for most queries I have run but this one is failing and I do not know why
code:
import math
import mysql.connector
config = {'user': 'allazzanni', 'password': 'not posting that here', 'host': 'also no', 'database': 'i could, but i wont'}
def queryDatabase (query):
cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
cursor.execute(query) #this is where the error is do stuff with the result
query = ("SELECT g.Grade FROM Grade = g, Topic = t WHERE g.idTopic = t.idTopic and t.nameTopic = %s")
print queryDatabase (query, 'math')
Expected:
the query to execute properly
Actual:
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'g.idTopic = t.idTopic and t.nameTopic = 'math'' at line 1