-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdbquery.py
36 lines (33 loc) · 1.11 KB
/
dbquery.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
import MySQLdb
#+++++++++++++++++++++++ MYSQL Syntax FOR CONNECTION +++++++++++++++++
#db = MySQLdb.connect(host="127.0.0.1",user="root",passwd="0000",db="MINDHACKS")
#cur =db.cursor()
#cur.execute("SELECT * FROM USERS")
#rows = cur.fetchall()
#for row in rows:
# for col in row:
# print "%s " % col
#db.close()
def fetchall(sql): #function that executes a query and returns its output/ read data from table
sql = str(sql)
db = MySQLdb.connect(host="127.0.0.1",user="root",passwd="0000",db="TOILO")
cur =db.cursor()
cur.execute(sql)
info = cur.fetchall()
db.close()
return info
def fetchone(sql): #function that executes a query and returns its output/ read data from table
sql = str(sql)
db = MySQLdb.connect(host="127.0.0.1",user="root",passwd="0000",db="TOILO")
cur =db.cursor()
cur.execute(sql)
info = cur.fetchone()
db.close()
return info
def inserttodb(sql): #function to write data to table
db = MySQLdb.connect(host="127.0.0.1",user="root",passwd="0000",db="TOILO")
cur =db.cursor()
cur.execute(sql)
db.commit()
db.close()
return 1