Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

Source Code of Py

This document describes creating a student management system using Python and MySQL. It connects to a MySQL database, defines functions to insert, view, update and delete student records, and provides a menu to allow the user to choose these options and interact with the student record database.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Source Code of Py

This document describes creating a student management system using Python and MySQL. It connects to a MySQL database, defines functions to insert, view, update and delete student records, and provides a menu to allow the user to choose these options and interact with the student record database.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#!

/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

You might also like