#!
/usr/bin/python
importMySQLdb
# Open database connection
db=MySQLdb.connect("localhost","testuser","test123","TESTDB")
# prepare a cursor object using cursor() method
cursor=db.cursor()
# execute SQL query using execute() method.
cursor.execute("SELECT VERSION()")
# Fetch a single row using fetchone() method.
data=cursor.fetchone()
print"Database version : %s "% data
# disconnect from server
db.close()
importos
import platform
importmysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",password="ammaamrita")
mycursor=mydb.cursor()
mycursor.execute("create database if not exists school")
mycursor.execute("use school")
exit='n'
while exit=='n':
os.system('cls')
print('-' * 90)
print('|'+' '*31+'STUDENT MANAGEMENT SYSTEM'+' ' * 32+ '|')
print('-' * 90)
print('| [I]nsert Record |', end='')
print(' [V]iew Record |', end='')
print(' [U]pdate Record |',end='')
print(' [D]elete Record |',end='')
print(' [E]XIT |')
print('-' * 90)
ch=input('YOUR Choice (I/V/U/D/E):')
ch = ch.upper()
ifch == 'I':
mydb=mysql.connector.connect(host="localhost", user="root", passwd="ammaamrita",
db="school")
mycursor=mydb.cursor()
choice='y'
while choice=='y':
sno=input('enter the roll number of student ')
sname=input('enter the name of student ')
print(" Creating Parkmaster12 table")
mycursor.execute("create table if not exists class12 (rnoint, name varchar(20))")
Qry = ("INSERT INTO class12 "\
"VALUES (%s, %s)")
data = (sno,sname)
mycursor.execute(Qry,data)
print('RECORD INSERTED SUCCESSFULLY')
choice=input('do you with to insert more records (y/n)')
if choice=='y':
continue
mydb.commit()
mydb.close()
elifch == 'V':
mydb=mysql.connector.connect(host="localhost", user="root", passwd="ammaamrita", db="school")
mycursor=mydb.cursor()
#mycursor.execute("""create table class12 (rnoint, name varchar(20))""")
choice='y'
while choice=='y':
rno=int(input('enter the roll number of student whose record you want to search '))
Qry = ("""select * from class12 WHERE rno = %s""")
data = (rno,)
mycursor.execute(Qry,data)
count=0