-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnect.py
76 lines (65 loc) · 2.08 KB
/
connect.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
71
72
73
74
75
76
import mysql.connector
from mysql.connector.constants import ClientFlag
def connection():
config = {
'user': 'root',
'password': 'testdbpwd',
'host': '104.198.52.49',
'client_flags': [ClientFlag.SSL],
'database': 'testdb',
'ssl_ca': 'server-ca.pem',
'ssl_cert': 'client-cert.pem',
'ssl_key': 'client-key.pem'
}
# now we establish our connection
cnxn = mysql.connector.connect(**config)
print(cnxn)
cursor = cnxn.cursor() # initialize connection cursor # create a new 'testdb' database
return cursor,cnxn
def fetchall():
c, conn = connection()
c.execute('''SELECT * from Student''')
rv = c.fetchall()
print(rv)
def createStudent():
c, conn = connection()
#c.execute('Create Database Attendancemgmt')
c.execute('CREATE TABLE Student (studentid int NOT NULL AUTO_INCREMENT,name varchar(255),email varchar(255), password varchar(255), filename varchar(255), PRIMARY KEY (studentid));')
conn.commit()
conn.close()
def createProfessor():
c, conn = connection()
c.execute('CREATE TABLE Professor(Profid int NOT NULL AUTO_INCREMENT,username varchar(255),email varchar(255),password varchar(255), Department varchar(255), PRIMARY KEY(Profid));')
conn.commit()
conn.close()
def createClass():
c, conn = connection()
c.execute('CREATE TABLE Professor(Classid int NOT NULL AUTO_INCREMENT,classname varchar(255),Pid int,Timings varchar(255),Totalmeets int, PRIMARY KEY(Classid),Foreign );')
conn.commit()
conn.close()
def createAttendance():
c, conn = connection()
c.execute('CREATE TABLE Attedance(Stid int,date varchar(255), Foreign Key(Stid) References Student(studentid) On delete Cascade On update cascade);')
def deleteRecord():
c, conn = connection()
#sql =
#val = (stid,)
c.execute("Delete From Student Where studentid=17")
conn.commit()
conn.close()
def setfkc():
c, conn = connection()
c.execute('SET FOREIGN_KEY_CHECKS = 0;')
conn.commit()
conn.close()
def truncateRecord():
c, conn = connection()
c.execute('Truncate Table Attedance')
conn.commit()
conn.close()
if __name__ == "__main__":
truncateRecord()
#i = 4
#while i<17:
# deleteRecord(i)
# i=i+1