Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mysql.connector
- import time
- from mysql.connector import errorcode
- try:
- con = mysql.connector.connect(
- user= 'root',
- password= '',
- host='localhost',
- database= 'testdb')
- print("Connected.")
- cursor = con.cursor()
- except mysql.connector.Error as e:
- if e.errno == errorcode.ER_ACCESS_DENIED_ERROR:
- print("Passwort // Username")
- elif e.errno == errorcode.ER_BAD_DB_ERROR:
- print("DataBase does not exist")
- else:
- print(e)
- def insert_temp(Temperatur_ID, Zeitpunkt, Wert, Thermometer_ID):
- query = "INSERT INTO Temperatur (Temperatur_ID, Zeitpunkt, Wert, Thermometer_ID)"
- "VALUES(%s, %s, %s, %s)"
- args= (Temperatur_ID, Zeitpunkt, Wert, Thermometer_ID)
- cursor.execute(query, args)
- con.commit()
- def main():
- # just test values so far
- value = 18.5;
- insert_temp(' ', time.strftime('%Y-%m-%d %H:%M:%S'), value, '1');
- cursor.close()
- con.close()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement