Last active
March 4, 2021 20:57
-
-
Save theDreamer911/5dd4cde6942365f645940109757d748e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MySQLdb | |
import csv | |
import sys | |
conn = MySQLdb.connect(host="127.0.0.1", user="root", password="", database="Fruit_Shop") | |
cursor = conn.cursor() | |
csv_data = csv.reader(open('products.csv')) | |
header = next(csv_data) | |
print('Importing the CSV Files') | |
for row in csv_data: | |
print(row) | |
cursor.execute( | |
"INSERT INTO product (id,name,price,stock) VALUES (%s, %s, %s, %s)", row) | |
conn.commit() | |
cursor.close() | |
print('Done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment