



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
mysql connectivity has been used to store data in mysql and work on python simultaneously.
Typology: Assignments
1 / 5
This page cannot be seen from the preview
Don't miss anything!




import mysql.connector print("\t\t----------------------------------------------------------") print("\t\t--****WELCOME TO SCHOOL MANAGEMENT SYSTEM****--") print("\t\t----------------------------------------------------------") print("\t\t------------NEW HORIZON SCHOOL-------------") print("\t\t----------------------------------------------------------") db=input("Do you have database? (y/n) : ") dname="" mydb="" mycursor="" if (db=='n'): dname=input("Enter new database name you want to create=") mydb=mysql.connector.connect(host='localhost',user='root',password='kramer#k ramer') mycursor=mydb.cursor() mycursor.execute("Create database "+dname) mydb=mysql.connector.connect(host='localhost',user='root',password='kramer#k ramer',database=dname) mycursor=mydb.cursor() mycursor.execute("create table student (Admno char(7) primary key,
Rollno int char(4),\Name char(20),Class varchar(5),
Stream varchar(20), Fees int") print("Student Tble Automatically Created in ",dname,"Database")
print("Its open for other operations now") else: dname=input("Enter existing Database name you want to open= ") mydb=mysql.connector.connect(host='localhost',user='root',password='kramer#k ramer',database=dname) print("Its open for other operations now") while (True): print("\t\t\t-------------MAIN MENU-------------") print(" \t\t\tPRESS 1: ADD RECORD") print(" \t\t\tPRESS 2: DISPLAY ALL RECORD") print(" \t\t\tPRESS 3: SEARCH STUDENT RECORD BY ROLLNO") print(" \t\t\tPRESS 4: DELETE STUDENT RECORD BY ROLLNO") print(" \t\t\tPRESS 5: UPDATE STUDENT RECORD") print(" \t\t\tPRESS 6: UPDATE STUDENTS' FEES RECORD") print(" \t\t\tPRESS 7: EXIT") print("\t\t\t-----------------------------------") choice=int(input("Enter Your Choice:")) if (choice==7): break elif (choice==1): a=input("Enter Admission Number: ")
myresult=mycursor.fetchall() t=mycursor.rowcount if(t!=0): print("Admno Rollno Name Class Stream Fees") for x in myresult: print(x[0]," ",x[1]," ",x[2]," ",x[3]," ",x[4]) else: print(" Invalid rollno. ") elif (choice==4): r1=input("Enter Student's rollno whose record you want to delete = ") mycursor=mydb.cursor() mycursor.execute(" Delete from student where rollno = " +r1) mydb.commit() t=mycursor.rowcount if(t!=0): print(" Found and Successfully Deleted ") else: print(" Invalid Rollno. ") elif (choice==5): r1=input("Enter Student's admno whose record you want to update ") course=input(" which record you want to update : ") newcourse=input("Enter data: ")
mycursor=mydb.cursor() mycursor.execute(" Update student set "+Course+"="+newcourse+" where admno= "+r1+) mydb.commit() t=mycursor.rowcount if(t!=0): print("Found and Successfully Updated") else: print("Invalid Rollno ") elif (choice==6): r1=input("Enter student rollno. whose fees you want to update= ") newfees=input("Update Fees (paid/not paid)= ") mycursor=mydb.cursor() mycursor.execute(" Update student set fees="+newfees+" wher rollno. = "+r1+) mydb.commit() t=mycursor.rowcount if(t!=0): print("Found and Successfully updated") else: print("Invalid rollno. ")