Simple credential management program
import mysql.connector
#use dictionary to define database credential
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="xxxxx",
database="xxxxx"
)
cursor = mydb.cursor()
cursor.execute ("select id, provider from dataemail order by id")
selectresult = cursor.fetchall()
print("================================")
print("Credential management program")
print("List of existing records : \n")
for x in selectresult:
print("-",x)
print("================================\n")
print("Insert new record here :")
PROVIDER = input("- Provider: ")
ID = input("- ID: ")
USERNAME = input("- Username: ")
EMAIL = input("- Email: ")
URL = input("- Url: ")
insertquery = "insert into dataemail (`id`, `username`, `email`, `url`, `provider`) values (%s,%s,%s,%s,%s)"
insertvalue = (ID,USERNAME,EMAIL,URL,PROVIDER)
cursor.execute(insertquery, insertvalue)
mydb.commit()
print(cursor.rowcount, "record inserted. \n")
print("================================\n")
print("List of new existing records : \n")
cursor.execute ("select id, provider from dataemail")
selectresult2 = cursor.fetchall()
for x in selectresult2:
print("-",x)
print("================================\n")