I am trying to connect to and insert into a MySQL database on my machine following this tutorial and I am stumped. Everything seems to look good up until the point where the the change is actually committed. I am getting an error:
Traceback (most recent call last):
File "write.py", line 18, in <module>
db.commit()
AttributeError: 'module' object has no attribute 'commit'
I have followed these instructions to install Python on my Mac and my code looks like this:
#!usr/bin/python
import MySQLdb as db
try:
con = db.connect(host='localhost', user='trevor', passwd='pw', db='aqi');
cur = con.cursor()
sql_statement = """INSERT INTO aqi(datetime, no2, o3, so2, co, pm10, pm25, aqi, health_range)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)"""
print sql_statement
cur.execute(sql_statement, ("some date", 13.2, 53.5, 45.4, 31.1, 31.1, 32.3, 33.4, "healthy"))
db.commit()
except db.Error, e:
print "Error %d: %s" % (e.args[0],e.args[1])
sys.exit(1)
finally:
if con:
con.close()
I haven't found any reference to this type of error anywhere and it really doesn't make sense. I would really appreciate any help or direction. Thanks!