import serial
import MySQLdb
dbConn = MySQLdb.connect("localhost","root”,”test”,”ISEF_DB") or die ("Could not connect to database")
cursor = dbConn.cursor()
device = '/dev/ttyACM0'
try:
print "Trying...",device
arduino = serial.Serial(device, 250000)
except:
print "Failed to connect on",device
try:
data = arduino.readline() #read data
# pieces = data.split("\t")
print "The data is:",data
try:
cursor.execute("UPDATE `ISEF_DB`.`attendance` SET `present`='1' WHERE `id` = 'data'")
dbConn.commit()
cursor.close()
print "data inserted"
except MySQLdb.IntegrityError:
print "Failed to insert data"
finally:
cursor.close()
print "done"
except:
print "Failed to get data"
When I execute this code, it seems like it is working, though it does not update the present cell to 1. If I change 'data'
to any known cell id, present is updated to 1. So, how do I update a cell from a variable?