could use some help

Supporting 2.7 and 3.2+
Post Reply
turbochardged
Fresh meat
Posts: 1
Joined: Wed Feb 08, 2017 9:30 am
Contact:

could use some help

Post by turbochardged »

I'm in the process of teaching myself python. so please excuse my ignorance.

I'm trying to run this statement only if the digital inputstate(True).


def insert_to_db(id_sensor, value_sensor):
db = MySQLdb.connect("localhost","root","raspberry","sensor_log" )
cursor = db.cursor()
time_sensor = time.time()
# Prepare SQL query to INSERT a record into the database.
sql = "INSERT INTO table_sensor_log(timestamp, sensor_id, sensor_value) VALUES ('%d', '%d', '%d' )" % (time_sensor,id_sensor ,value_sensor)

try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
db.close()
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests