kpuz
December 18th, 2012, 11:14 PM
I have a scraper that I need to configure to push data into a mysql database table. I have already created a table and a non-root user that has access to it. Here is the test script:
import MySQLdb
db=MySQLdb.connect(host="localhost",user="scraper",passwd="getrich",db="mlsto")
cur=db.cursor()
date="2055-01-19"
listings=66
cur.execute("INSERT INTO housedates (date,listings) VALUES(%s,%s)", (date,listings))
sql="SELECT * FROM housedates"
cur.execute(sql)
results=cur.fetchall()
cur.close()
print results
the output of this script is:
((datetime.date(2012, 12, 12), 23), (datetime.date(2012, 12, 12), 23), (datetime.date(2055, 1, 19), 66))
The first two rows were placed in the table by me using the mysql command line, the third row is added by python.
When I list out all the rows of this table using command-line, I don't see the row added by python. What gives? I'm not sure how to go about troubleshooting this. Any tips?
import MySQLdb
db=MySQLdb.connect(host="localhost",user="scraper",passwd="getrich",db="mlsto")
cur=db.cursor()
date="2055-01-19"
listings=66
cur.execute("INSERT INTO housedates (date,listings) VALUES(%s,%s)", (date,listings))
sql="SELECT * FROM housedates"
cur.execute(sql)
results=cur.fetchall()
cur.close()
print results
the output of this script is:
((datetime.date(2012, 12, 12), 23), (datetime.date(2012, 12, 12), 23), (datetime.date(2055, 1, 19), 66))
The first two rows were placed in the table by me using the mysql command line, the third row is added by python.
When I list out all the rows of this table using command-line, I don't see the row added by python. What gives? I'm not sure how to go about troubleshooting this. Any tips?