-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent_record_database.py
70 lines (65 loc) · 1.94 KB
/
student_record_database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import mysql.connector as MySQLdb
from tkinter import messagebox
def load():
con=MySQLdb.connect(
host="localhost",
user="root",
password="swing",
database="student_records"
)
cur=con.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS student(id INTEGER PRIMARY KEY, sname TEXT, sroll TEXT, smarks TEXT)")
con.commit()
cur.execute("SELECT * FROM student")
rows=cur.fetchall()
con.close()
return rows
def search(user="root", password="swing"):
con=MySQLdb.connect(
host="localhost",
user="root",
password="swing",
database="student_records"
)
cur=con.cursor()
cur.execute("SELECT * FROM student WHERE user=? AND password=?",(user, password))
rows=cur.fetchall()
con.close()
return rows
def add(name, roll, marks):
con=MySQLdb.connect(
host="localhost",
user="root",
password="swing",
database="student_records"
)
cur=con.cursor()
cur.execute("INSERT INTO student (sname, sroll, smarks) VALUES(%s, %s, %s)",(name, roll, marks))
con.commit()
con.close()
messagebox.showinfo('Admin', 'Record Added Successfully!!')
def delete(roll):
con=MySQLdb.connect(
host="localhost",
user="root",
password="swing",
database="student_records"
)
cur=con.cursor()
cur.execute("DELETE FROM student WHERE sroll=%s",(roll,)) #comma should be there.
con.commit()
con.close()
messagebox.showinfo('Admin', 'Record Deleted Successfully!!')
def edit(name, roll, marks, id1):
con=MySQLdb.connect(
host="localhost",
user="root",
password="swing",
database="student_records"
)
cur=con.cursor()
m=int(marks)
cur.execute("UPDATE student set sname=%s, sroll=%s, smarks=%s WHERE id=%s",(name, roll, m, id1))
con.commit()
con.close()
messagebox.showinfo('Admin', 'Record Updated Successfully!!')