Professional Documents
Culture Documents
my efforts in all the stages of this project work. I would also like to
Signature of principal
_________________________
INDEX
Certification of excellence
Acknowledgement
Brief Overview of Project
Software and Hardware requirement
Advantages of Project
Limitations of Project
Source Code of Project
Output Screens
Future Enhancement of Project
Bibliography
Brief Overview of the project
“Ecommerce Management”
5. Order Management:
The script introduces an 'orders' table to manage
7. Error Handling:
A robust error-handling mechanism is implemented
Database Management:
import mysql.connector
try:
mydb = mysql.connector.connect(
host='localhost',
user='root',
password='svps',
database='ecom_db'
)
c = mydb.cursor()
c.execute("create database if not exists ecom_db")
# Database configuration
db_config = {
'host': 'localhost',
'user': 'root',
'password': 'svps',
'database': 'ecom_db',
}
mydb = mysql.connector.connect(
host='localhost',
user='root',
password='svps',
database='ecom_db'
)
c = mydb.cursor()
c.execute(insert_query, values)
mydb.commit()
c.execute(insert_query, values)
mydb.commit()
print("\nProducts:")
c.execute("SELECT product_id, name, price FROM products")
products = c.fetchall()
for product_id, name, price in products:
print(f"Product ID: {product_id}, Name: {name}, Price: {price}")
print("\nCustomers:")
c.execute("SELECT customer_id, username FROM customers")
for customer_id, username in c:
print(f"Customer ID: {customer_id}, Username: {username}")
c.execute(insert_order_query, order_values)
mydb.commit()
# Print the saved order
print("\nOrder Details:")
print(f"Order Date: {order_date}")
print(f"Product ID: {product_id}")
print(f"Customer ID: {customer_id}")
print(f"Quantity: {quantity}")
print(f"Total Price: {total_price:.2f}")
finally:
# Close the cursor and database connection in the 'finally' block
to ensure it's done regardless of success or failure
if 'c' in locals() and c is not None:
c.close()
if 'mydb' in locals() and mydb is not None:
mydb.close()
import mysql.connector
mydb =
mysql.connector.connect(host='localhost',user='root',password='s
vps',database='ecom_db')
c = mydb.cursor()
print("\nOrders:")
c.execute("SELECT orders.order_id, customers.username,
products.name, products.price, orders.quantity FROM orders "
"INNER JOIN customers ON orders.customer_id =
customers.customer_id "
"INNER JOIN products ON orders.product_id =
products.product_id")
orders = c.fetchall()
for order_id, customer_username, product_name, product_price,
quantity in orders:
total_price = product_price * quantity
print(f"Order ID: {order_id}")
print(f"Customer: {customer_username}")
print(f"Product: {product_name}")
print(f"Price: {product_price}")
print(f"Quantity: {quantity}")
print(f"Total Price: {total_price}")
print()
# Database configuration
db_config = {
'host': 'localhost',
'user': 'root',
'password': 'svps',
'database': 'ecom_db',
}
def create_connection():
try:
connection = mysql.connector.connect(**db_config)
return connection
except mysql.connector.Error as err:
print(f"Error: {err}")
return None
def get_order_info(order_id):
connection = create_connection()
if connection:
cursor = connection.cursor(dictionary=True)
cursor.execute("SELECT orders.order_id, customers.username,
products.name, products.price, orders.quantity "
"FROM orders "
"INNER JOIN customers ON orders.customer_id =
customers.customer_id "
"INNER JOIN products ON orders.product_id =
products.product_id "
"WHERE orders.order_id = %s", (order_id,))
order_info = cursor.fetchone()
cursor.close()
connection.close()
return order_info
return None
def print_invoice(order_id):
order_info = get_order_info(order_id)
if order_info:
print("Invoice")
print("Order ID:", order_info['order_id'])
print("Customer:", order_info['username'])
print("Product:", order_info['name'])
print("Price:", order_info['price'])
print("Quantity:", order_info['quantity'])
total_price = order_info['price'] * order_info['quantity']
print("Total Price:", total_price)
Create products table and customers table and insert values into
both tables.
Create orders table, insert values intotable to create an order.
To print invoice