Created
September 29, 2018 20:02
-
-
Save GideonBabu/0829dafe9c78020aa70e42e51f52f3ed to your computer and use it in GitHub Desktop.
Python MySQLDB insert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import MySQLdb | |
import datetime | |
# Open database connection | |
db = MySQLdb.connect("localhost","root","","know_your_beat" ) | |
# prepare a cursor object using cursor() method | |
cursor = db.cursor() | |
current_time = datetime.datetime.utcnow() | |
# Prepare SQL query to INSERT a record into the database. | |
sql = """INSERT INTO current_heart_beat(bpm,tyme) | |
VALUES ('50', '2012-12-15 11:15:09.205000')""" | |
try: | |
# Execute the SQL command | |
cursor.execute(sql) | |
# Commit your changes in the database | |
db.commit() | |
except: | |
# Rollback in case there is any error | |
db.rollback() | |
# disconnect from server | |
db.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment