-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql_query.py
44 lines (35 loc) · 1.03 KB
/
mysql_query.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
import datetime
import mysql.connector
from mysql.connector import errorcode
import pdb
def init_session() :
try:
our_db = mysql.connector.connect(
host ="35.243.97.54",
user="root",
password="asdf;lkj",
database="food"
)
return our_db
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print ("Somthing is wrong with your ser name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else :
print(err)
else:
our_db.close()
def single_select(cnx,sel,frm):
cursor = cnx.cursor()
query = "SELECT {0} FROM {1} ".format(sel,frm)
print(query)
def get_db_all(cnx):
cursor = cnx.cursor()
query = "SELECT * FROM fooddata"
iterator = cursor.execute(query, params=None, multi=True)
pdb.set_trace()
for row in cursor:
print(row)
aa = init_session()
get_db_all(aa)