0% found this document useful (0 votes)
6 views

Annual-Project

The document is a Python program that manages a student database using MySQL. It includes functions to create a database and table, insert, search, modify, delete, and display student records. The program interacts with the user through a command-line interface to perform these operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Annual-Project

The document is a Python program that manages a student database using MySQL. It includes functions to create a database and table, insert, search, modify, delete, and display student records. The program interacts with the user through a command-line interface to perform these operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

#PROGRAM

import sys
import mysql.connector
from mysql.connector import Error

#[ADM, NAME, DOB, STREAM]


def createDB():
mydb=mysql.connector.connect\
(host="localhost", user="root", passwd="tiger")
mycursor=mydb.cursor()
mycursor.execute("create database SCHOOL89")
mydb.commit()
mycursor.close()
mydb.close()

def createTable():
mydb=mysql.connector.connect(host="localhost",\
user="root",\
passwd="tiger",\
database="school89")
mycursor=mydb.cursor()
mycursor.execute("create table student(\
Adm int(5) primary key,\
Name varchar(35),\
DOB date, stream varchar(15))")
#mycursor.commit()
mycursor.close()
mydb.close()

def AdmSearch():
mydb=mysql.connector.connect(host="localhost", user='root',\
passwd='tiger', database='school89')
cursor=mydb.cursor()
A=int(input("Enter Adm No to search: "))
sql="select * from student where adm={}".format(A)
#sql="select * from student where adm="+str(A)
cursor.execute(sql)
for row in cursor:
print(row)
cursor.close()
mydb.close()

def StreamSearch():
mydb=mysql.connector.connect(host="localhost", user='root',\
passwd='tiger', database='school89')
cursor=mydb.cursor()
S=input("Enter Stream to search: ")
sql="select * from student where stream='{}'".format(S)
#sql="select * from student where stream="+str('\'')+S+str('\'')
cursor.execute(sql)
data=cursor.fetchall()
for row in data:
print(row)
cursor.close()
mydb.close()
def YearSearch():
mydb=mysql.connector.connect(host="localhost", user='root',\
passwd='tiger', database='school89')
cursor=mydb.cursor()
sql="select * from student where dob like '2000%'"
cursor.execute(sql)
for row in cursor:
print(row)
cursor.close()
mydb.close()

def Insert():
mydb=mysql.connector.connect(host="localhost", user="root",\
passwd="tiger", database="school89")
cursor=mydb.cursor()
Adm=int(input("Adm No: "))
Name=input("Name: ")
DOB=input("DOB(yyyy-mm-dd): ")
stream=input("Stream: ")
sql="insert into student values\
({},'{}','{}','{}')".format(Adm, Name, DOB, stream)
cursor.execute(sql)
mydb.commit()
cursor.close()
mydb.close()

def Delete():
mydb=mysql.connector.connect(host="localhost", user='root',\
passwd='tiger', database='school89')
cursor=mydb.cursor()
A=int(input("Enter Adm No to delete: "))
sql="delete from student where adm={}".format(A)
cursor.execute(sql)
mydb.commit()
cursor.close()
mydb.close()

def Modify():
mydb=mysql.connector.connect(host="localhost", user='root',\
passwd='tiger', database='school89')
cursor=mydb.cursor()
A=int(input("Enter Adm No to update record: "))
N=input("Enter correct name: ")
sql="update student set name='{}' where adm={}".format(N,A)
cursor.execute(sql)
mydb.commit()
cursor.close()
mydb.close()

def Display():
try:
db = mysql.connector.connect(host='localhost',\
database='school89', user='root', password='tiger')
if db.is_connected():
print('Connected to MySQL database')
except Error as e:
print(e)
return
#sys.exit() ->to kill program execution
pysql=db.cursor()
pysql.execute("select * from student")
data=pysql.fetchall()
for row in data:
print(row)
pysql.close()
db.close()

createDB()
createTable()
for i in range(3):
Insert()
choice=1
while choice!=5:
print("Enter your choice:-")
print("1. Search Record")
print("2. Delete Record")
print("3. Modify Record")
print("4. Display")
print("5. Exit")
choice=int(input("Enter your choice:-"))
if choice==1:
print('SEARCH PROCESS STARTS NOW:-')
print('1. Search by Adm No')
print('2. Search by Stream')
print('3. Search by Year')
op=int(input('Enter your choice:-'))
if op==1:
AdmSearch()
elif op==2:
StreamSearch()
elif op==3:
YearSearch()
else:
print('Invalid option entered')
elif choice==2:
Delete()
elif choice==3:
Modify()
elif choice==4:
Display()
else:
print("Thank you")

#OUTPUT

Adm No: 1
Name: Kaibalya
DOB(yyyy-mm-dd): 2008-09-25
Stream: Science
Adm No: 2
Name: Gourish
DOB(yyyy-mm-dd): 2007-08-28
Stream: Commerce
Adm No: 3
Name: Kritarth
DOB(yyyy-mm-dd): 2006-06-29
Stream: Humanities
Enter your choice:-
1. Search Record
2. Delete Record
3. Modify Record
4. Display
5. Exit
Enter your choice:-1
SEARCH PROCESS STARTS NOW:-
1. Search by Adm No
2. Search by Stream
3. Search by Year
Enter your choice:-1
Enter Adm No to search: 1
(1, 'Kaibalya', datetime.date(2008, 9, 25), 'Science')
Enter your choice:-
1. Search Record
2. Delete Record
3. Modify Record
4. Display
5. Exit
Enter your choice:-3
Enter Adm No to update record: 1
Enter correct name: Sidharth
Enter your choice:-
1. Search Record
2. Delete Record
3. Modify Record
4. Display
5. Exit
Enter your choice:-4
Connected to MySQL database
(1, 'Sidharth', datetime.date(2008, 9, 25), 'Science')
(2, 'Gourish', datetime.date(2007, 8, 28), 'Commerce')
(3, 'Kritarth', datetime.date(2006, 6, 29), 'Humanities')
Enter your choice:-
1. Search Record
2. Delete Record
3. Modify Record
4. Display
5. Exit
Enter your choice:-2
Enter Adm No to delete: 2
Enter your choice:-
1. Search Record
2. Delete Record
3. Modify Record
4. Display
5. Exit
Enter your choice:-4
Connected to MySQL database
(1, 'Sidharth', datetime.date(2008, 9, 25), 'Science')
(3, 'Kritarth', datetime.date(2006, 6, 29), 'Humanities')
Enter your choice:-
1. Search Record
2. Delete Record
3. Modify Record
4. Display
5. Exit
Enter your choice:-1
SEARCH PROCESS STARTS NOW:-
1. Search by Adm No
2. Search by Stream
3. Search by Year
Enter your choice:-1
Enter Adm No to search: 2
Enter your choice:-
1. Search Record
2. Delete Record
3. Modify Record
4. Display
5. Exit
Enter your choice:-5
Thank you

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy