I am attempting to insert data into a MySQL database. I am using python 2.7 and I am using the mysql.connector.
My error is:
mysql.connector.errors.ProgrammingError: 1064 (4200): 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 '%s) at line 1.
This indicates a error in my code where I attempt to insert my variable np (VALUES (%s)");). np is a "noun-phrase" such as a "skate board".
import mysql.connector
from textblob import TextBlob
cnx = mysql.connector.connect(user='XXX', password='XXX',
host='XXXXX',
database='XXXX')
cursor = cnx.cursor(buffered=True)
Latest = ("SELECT * FROM SentAnalysis")
cursor.execute(Latest)
for row in cursor.fetchall():
SentText = row[2]
blob = TextBlob(SentText)
for np in blob.noun_phrases:
print(np)
SQLInsertCmd = ("INSERT INTO TestNounPhrase (NPhrase) VALUES (%s)")
cursor.execute(SQLInsertCmd,np)
cnx.commit()
cursor.close()
cnx.close()
The example from the manual is https://dev.mysql.com/doc/connector-python/en/connector-python-example-cursor-transaction.html. e.g.
"VALUES (%s, %s, %s, %s, %s)")
I can't see a difference. This error is also discussed in detail here : How can I fix MySQL error #1064? Other similar examples on stackoverflow have been linked to reserved words, Redundant comas .But looking at these examples I can't spot an obvious error.
Any suggestions on where I am going wrong would be much appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…