-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql-menu.py
More file actions
41 lines (30 loc) · 1.08 KB
/
mysql-menu.py
File metadata and controls
41 lines (30 loc) · 1.08 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
import mysql
import mysql.connector
cnx = mysql.connector.connect(user='root', password='',
host='127.0.0.1',
database='menu')
cur = cnx.cursor()
# Use all the SQL you like
cur.execute("SELECT * FROM fish ")
# print all the first cell of all the rows
for row in cur.fetchall():
print(row[0],"-->",row[1],"@",row[2],"each")
print("---------------------------------------")
print(" WHERE price > 7")
print("---------------------------------------")
cur.execute("SELECT * FROM fish WHERE price > 7")
# print all the first cell of all the rows
for row in cur.fetchall():
print(row[0],"-->",row[1],"@",row[2],"each")
# Modifying the results
operation = input("entrez l'operation = : ")
value = input("value: ")
cur.execute("SELECT * FROM fish WHERE price %s %s" %(operation, value))
# print all the first cell of all the rows
for row in cur.fetchall():
print(row[0],"-->",row[1],"@",row[2],"each")
statement = """SHOW TABLES"""
cur.execute(statement)
table_list = []
for record in cur.fetchall():
table_list.append(record[0])