I'm hoping someone can help me? I'm trying to populate a MySQL database using Python 2.7 and the MySQLdb library. I've written the sample script below but no matter what I try, I can't get it to work.
The code runs without an error (it prints the 'Done' when I run the code but that's it) and when I try the query directly in phpMyAdmin it works fine, for some reason I can't get it to work from within Python.
Have I missed something? Is there something I need to activate in phpMyAdmin to get it to work? I've been searching around for most of the afternoon for an answer, when other people have similar problems though they tend to get error messages (which I don't).
import MySQLdb
# Define the database access details
DB_HOST = "localhost"
DB_USER = "username"
DB_PASSWORD = "secretpassword"
DB_NAME = "TestDatabase"
# Establish the connection to the database
db = MySQLdb.connect(
host=DB_HOST,
user=DB_USER,
passwd=DB_PASSWORD,
db=DB_NAME
)
cur = db.cursor()
Query = "INSERT INTO SearchResults ( `TimeStamp`, `SearchTerm`, `SearchResult`) VALUES ('2013-06-22 17:28:09', 'TestSearchTerm', 'Test Search Result');"
cur.execute(Query)
print"Done"
This is my first experience with any of this so if I've overlooked something obvious, please forgive me! Any help would be appreciated!