forked from bakerj32/gef
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysqlInsert.py
More file actions
15 lines (15 loc) · 743 Bytes
/
mysqlInsert.py
File metadata and controls
15 lines (15 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import MySQLdb as mdb
import conf
def insert_data(data):
try:
# Replace the parameters here for using a different mysql server
conn = mdb.connect(host=conf.server, user=conf.writer_username, passwd=conf.writer_password, db=conf.db)
cur = conn.cursor()
for row in data:
#Insert each row of the array into the database
cur.execute("INSERT INTO Entry (source, date, type, cost, units_total, total_cost) VALUES (%s, %s, %s, %s, %s, %s)", (row['source'], row['date'], row['type'], row['cost'], row['units_total'], row['total_cost']))
conn.commit()
conn.close()
except mdb.Error, e:
#Print any mysql errors.
print "Error %d: %s" % (e.args[0],e.args[1])