Skip to content

Instantly share code, notes, and snippets.

@GideonBabu
Created September 29, 2018 20:02
Show Gist options
  • Save GideonBabu/0829dafe9c78020aa70e42e51f52f3ed to your computer and use it in GitHub Desktop.
Save GideonBabu/0829dafe9c78020aa70e42e51f52f3ed to your computer and use it in GitHub Desktop.
Python MySQLDB insert
#!/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