Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- import sys
- def printDB():
- result = conn.execute("SELECT ID, Username, Password FROM Accounts")
- for row in result:
- print("Account Number: ", row[0])
- print("Username: ", row[1])
- print("Password: ", row[2])
- #creates the db if not present
- conn = sqlite3.connect('accounts.db')
- #traverse through returned information
- theCurser = conn.cursor()
- try:
- #create table
- conn.execute("CREATE TABLE Accounts(ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, Username TEXT NOT NULL, Password TEXT);")
- conn.commit()
- print("Table Created")
- except sqlite3.OperationalError:
- print("Table could not be created.")
- catpjs = input("What is you Username",)
- catssox = input("What is your pw",)
- conn.execute("INSERT INTO Accounts(Username, Password) VALUES (?, ?)", (catpjs, catssox))
- conn.commit()
- printDB()
- #always close db after use
- conn.close()
- print("Database Terminated.")
Add Comment
Please, Sign In to add comment