-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql_exemple.py
More file actions
64 lines (51 loc) · 1.5 KB
/
Copy pathmysql_exemple.py
File metadata and controls
64 lines (51 loc) · 1.5 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
57
58
59
60
61
62
63
64
import mysql.connector as mc
from me import me
# connection a la base de donnee
mydb = mc.connect(
host = 'localhost',
user = 'kaba',
password = me.me,
# database = 'Eleves'
)
# print(mydb)
mycursor = mydb.cursor()
# mycursor.execute("CREATE DATABASE mydatabase")
# mycursor.execute("""CREATE TABLE marks(
# devoir int not null,
# exam int not null
# )""")
# mycursor.execute("ALTER TABLE marks ADD COLUMN id int auto_increment primary key")
# for x in mycursor:
# print(x)
sql = "INSERT INTO marks (devoir, exam, matiere) VALUES (%s, %s, %s)"
# val = [
# (10, 11, "HG"),
# (11, 13, "Philo"),
# (12, 12, "ESP"),
# (13, 17, "ART"),
# (14, 16, "ESP"),
# (15, 15, "SVT"),
# (16, 13, "PORTUGUES"),
# (17, 13, "PYTHON"),
# (18, 16, "JAVA"),
# (19, 13, "JAVASCRIPT"),
# (20, 19, "ML"),
# (11, 15, "AI"),
# (12, 18, "DL"),
# (13, 18, "NLP"),
# (14, 20, "SQL"),
# (15, 19, "MYSQL")
# ]
val = (12, 18, "Physique")
# mycursor.executemany(sql, val) #when you insert a lot of values at once
# mycursor.execute(sql, val)
# mydb.commit() # indispensable pour appliquer les changements
# print(mycursor.rowcount, "record inserted:")
# print(mycursor.lastrowid)
mycursor.execute("SELECT devoir, matiere FROM marks LIMIT 5,10")
myresult = mycursor.fetchone()
#
# for res in myresult:
# print(res)
print(myresult)
auto = "'Fisker' 'Ford' 'Ford' 'Mustang' 'Fuso' 'GAZ' 'Ginetta' 'GMC' 'Grecav' 'Gumpert' 'Hispano' 'Suiza' 'Hommell' 'Honda'"