-
Notifications
You must be signed in to change notification settings - Fork 0
/
NASA-conn.py
48 lines (35 loc) · 1.03 KB
/
NASA-conn.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
#!/usr/bin/python
# NFC Attendance System
# Date Last Modified : 24-03-2015
# Authors : Anagh Kumar Baranwal, Manush Bhatt, Arnav Nag
# License : GPLv3
import MySQLdb
def init():
db = MySQLdb.connect(host="localhost",user="admin",passwd="admin123",db="nasadb")
cur=db.cursor()
sql = """CREATE TABLE STUDENT (
C_ID INT NOT NULL,
R_ID INT(10) NOT NULL,
FIRST_NAME CHAR(20) NOT NULL,
LAST_NAME CHAR(20),
AGE INT,
PRIMARY KEY (R_ID) )"""
cur.execute(sql)
db.close()
def add(values):
db = MySQLdb.connect(host="localhost",user="admin",passwd="admin123",db="nasadb")
cur=db.cursor()
sql = """INSERT INTO STUDENT VALUES (VALUES)"""
cur.execute(sql)
db.close()
def check(value):
db = MySQLdb.connect(host="localhost",user="admin",passwd="admin123",db="nasadb")
cur=db.cursor()
sql = " SELECT * FROM STUDENT WHERE C_ID = ? ", (value,)
cur.execute(sql)
# USE cursor.fetchone()[0] if using COUNT(*)
row = cur.fetchnone()
if row is None:
print "Invalid ID"
else:
print "WELCOME ",row[1]