-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql adding rows
More file actions
61 lines (45 loc) · 1.78 KB
/
sql adding rows
File metadata and controls
61 lines (45 loc) · 1.78 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
import mysql.connector
def insertproduct(Name, Price , imageUrl,Description):
connection = mysql.connector.connect(host = "localhost", user = "root",password = "147914",database="node-app")
cursor = connection.cursor()
sql = "INSERT INTO Products(Name,Price,imageUrl,Description) VALUES (%s,%s,%s,%s)"
values = (Name, Price,imageUrl,Description)
cursor.execute(sql,values)
try:
connection.commit()
print(f"{cursor.rowcount} tane kayit eklendi")
print(f"son eklenen kaydin id no su {cursor.lastrowid}")
except mysql.connector.Error as err:
print("hata",err)
finally:
connection.close()
print("database kapandı")
def insertproducts(list):
connection = mysql.connector.connect(host = "localhost", user = "root",password = "147914",database="node-app")
cursor = connection.cursor()
sql = "INSERT INTO Products(Name,Price,imageUrl,Description) VALUES (%s,%s,%s,%s)"
values = list
cursor.executemany(sql,values)
try:
connection.commit()
print(f"{cursor.rowcount} tane kayit eklendi")
print(f"son eklenen kaydin id no su {cursor.lastrowid}")
except mysql.connector.Error as err:
print("hata",err)
finally:
connection.close()
print("database kapandı")
liste = []
while True:
name = input("urun adini giriniz")
price = input("urun fiyati giriniz")
imageurl = input("urun resim adi giriniz")
description = input("urun aciklamasi giriniz")
liste.append((name,price,imageurl,description))
result = input("devam etmek istiyor musunuz(e-h)")
if result == "h":
print("kayitlariniz veritabanina aktariliyor.")
print(liste)
insertproducts(liste)
break
#insertproduct(name,price,imageurl,description)