Thursday, March 5, 2020

How to insert data into my sql using python language using menu program


from tkinter import *
import pymysql

def create_table():
    mycursor.execute("CREATE TABLE MM32 (id INT AUTO_INCREMENT PRIMARY KEY, PartNo VARCHAR(255),ARMVer VARCHAR(255), MaxSpeed VARCHAR(255),Flash VARCHAR(255),RAM VARCHAR(255),GPIO VARCHAR(255),AdvTimer VARCHAR(255),GPTM VARCHAR(255),WDG VARCHAR(255),RTC VARCHAR(255) )")
    print("Table created")

def View_table():
    mycursor.execute("SELECT * FROM MM32")
    row = mycursor.fetchone() 
    while row is not None:
        print(row)
        row = mycursor.fetchone()

conn=pymysql.connect(host="localhost",user="root",password="",db="sslabs")
mycursor=conn.cursor()


#main code start here
print("\n1.create a table")
print("\n2.insert into table")
print("\n3.View  table")
x=int(input("enter your choice:::"))
if x==1:
    create_table()
elif x==3:
    View_table()
 
elif x==2:
    sql = "INSERT INTO MM32 (PartNo, ARMVer, MaxSpeed,Flash,RAM,GPIO,AdvTimer,GPTM,WDG,RTC) VALUES (%s, %s ,%s,%s, %s ,%s,%s,%s, %s ,%s)"
    PartNo=input("enter mm32 part")
    ARMVer=input("enter your arm_version")
    MaxSpeed=input("enter your MaxSpeed")
    Flash=input("enter your Flash")
    RAM=input("enter your RAM")
    GPIO=input("enter your GPIO")
    AdvTimer=input("enter your AdvTimer")
    GPTM=input("enter your GPTM")
    WDG=input("enter your WDG")
    RTC=input("enter your RTC")
    val = (PartNo, ARMVer,MaxSpeed,Flash,RAM,GPIO,AdvTimer,GPTM,WDG,RTC)
    mycursor.execute(sql, val)
    print(mycursor.rowcount, "record inserted.")
#mycursor.execute(sql, val1)
else :
    print("please enter above options only")

conn.commit()

No comments:

Post a Comment

python class topic video