-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_util1.py
More file actions
57 lines (39 loc) · 1.22 KB
/
db_util1.py
File metadata and controls
57 lines (39 loc) · 1.22 KB
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
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="23456",
database="student_db1"
)
cursor=mydb.cursor()
def inseartInToStudentDb(inputTuple):
c = 'insert into student_db1 (ID,NAME,AGE,SUBJECT,ADDRESS) values(%s,%s,%s,%s,%s)'
cursor.execute(c,inputTuple)
mydb.commit()
def getStudetCount(Id):
cursor.execute('Select Count(*) From student_db1 Where ID = ' + str(Id))
myresult = cursor.fetchone()
return(myresult[0])
def fineIdStudentDb(Id):
a = ("select * from student_db1 where ID = " + str(Id))
cursor.execute(a)
b = cursor.fetchall()
return(b)
def udateStudentAge(inputTuple):
a = ('UPDATE student_db1 SET AGE = %s WHERE ID = %s')
cursor.execute(a,inputTuple)
mydb.commit()
def udateStudentAddress(inputTuple):
a = ('UPDATE student_db1 SET ADDRESS = %s WHERE ID = %s')
cursor.execute(a,inputTuple)
mydb.commit()
def udateStudentSubject(inputTuple):
a = ('UPDATE student_db1 SET SUBJECT = %s WHERE ID = %s')
cursor.execute(a,inputTuple)
mydb.commit()
def deleteStudenRecord(ID):
a = ('DELETE FROM student_db1 WHERE ID = ' +str(ID))
cursor.execute(a)
mydb.commit()
if __name__ == '__main__':
deleteStudenRecord(8)