example Python 3 code to entering data at Mysql database

this is an example Python 3 code, everyone can use to make a sample data entering at Mysql database


import pymysql
import time
import serial
ser =serial.Serial(port='/dev/ttyUSB0',baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, timeout=2)
connection=pymysql.connect(host='localhost',
                           user='root',
                           password='',
                           db='zigbee',
                           charset='utf8mb4',
                           cursorclass=pymysql.cursors.DictCursor)
try:
    with connection.cursor() as cursor:
        # Create a new record
        sql="insert into user(email,password)VALUES (%s, %s)"
        cursor.execute(sql, ('puputdani@merl.jp','grace3112'))
       
        connection.commit()
       
        with connection.cursor() as cursor:
            #read the single record
            sql="select 'id', 'password' from user WHERE 'email' = %s"
            cursor.execute(sql, ('puput.danny@gmail.com'))
            result=cursor.fetchone()
            print(result)
finally:


    connection.close()

thanks very much, arigato gozaimasu

Komentar

Postingan populer dari blog ini

IEEE Format