Boutique Management System using Python-MySQL Connectivity
In this article, we are going to make a simple project on a boutique management system using Python MySql connectivity.
This is a boutique management system made using MySQL connectivity with Python. It uses a MySQL database to store data in the form of tables and to maintain a proper record of all details. Different SQL queries that include DDL, DQL, DML, and DCL commands are used in this project which is useful to perform CRUD (Create, Read, Update, Delete) operations using MySQL. This management system provides a common platform for customers, employees, as well employers to use the services. The various functionalities provided in this system are:
Customers: Customer can create their accounts, sign in to their accounts and perform various operations such as book their orders, view booking, delete bookings and update their details.
Employees: Employees can sign in to their account using their employee id and perform operations such as updating delivered orders of customers, adding a new product, and deleting a product.
Employer: The employer can perform two operations which are viewing product details and adding a new employee.
MySQL should be installed on our system. Refer to this link to Download the MySQL installer. Once MySQL Server is installed properly, we can create databases and tables using MySQL commands in MySQL Command-Line-Client. MySQL Command Line Client is installed together with the MySQL Server, so you don’t need to download and install the MySQL client separately. To check whether you have the client program on your machine, go to search, and type “MySQL”. To access MySQL Server from the command-line client, open the program and enter the password after that, you will be able to use the client.
The tables used for this Boutique Management System are made using MySQL Command-Line-Client.
Note: Refer to this article to know more about how to create databases and tables.
CREATE DATABASE sboutique; USE sboutique;
Creating customer table
The customer table has 6 columns, which store customer ID, customer name, last name, customer’s phone number, address of the customer, and products booked.
create table customer ( cust_id int(8) PRIMARY KEY, c_nam varchar(30), c_lnam varchar(30), c_phno varchar(10), c_adrs varchar(50), bkd_pro varchar(40) );
Here cust_id is made the primary key because each customer is considered to be unique.
Creating employee table
The employee table has 5 columns which stores, employee ID, employee name, last name, phone number, and address.
create table employee ( emp_id char(3) PRIMARY KEY, e_nam varchar(30), e_lnam varchar(30), e_phno varchar(10), e_adrs varchar(30),);
Here employee ID is made the primary key because each employee is considered to be unique.
Creating products table
The products table has 4 columns with columns product number, product id, product price, and product stock.
create table products ( pro_num char(5), pro_id char(10) PRIMARY KEY, pro_price int(6), pro_stk int(5) );
Here product ID is made as the primary key because each product in the database has a unique ID.
Let’s insert some products into the products table.
INSERT INTO products VALUES ('1','KWPTP25',330,18), ('2','KWPTP30',450,30), ('3','KWPTP45',650,20), ('4','SSST025',850,10), ('5','SSST030',350,12);
These 5 records are now added to the table.
Let’s check the description and contents in the table. Type the following command in MySQL Command-Line-Client.
Checking the table structure and data stored in the table
USE sboutique; SHOW TABLES;
To view entered records in the table, execute the below command :
SELECT * FROM products;
Now the tables are created in the database. This database can be used to store create records, update values in tables, and delete records.
We need to make a connection between the MySQL database and Python so that the tables can be accessed using python IDE. For making a connection we need to install mysql-connector which can be done by writing the following command in the command prompt on Windows.
pip install mysql-connector-python
After installation of the mysql-connector, we can connect MySQL with Python which can be done by writing the following code.
In the above code, we have to enter our localhost address, port number, and password that we have set while installing MySQL workbench It will look like the below image after setup MySQL workbench also we have to enter the database name on which we worked on.
Database and Tables in Use :
The name of the MySQL Database used is “sboutique” and the following tables are used :
Functions in the program
1. Check() Function
This function is being used to return a list of IDs of all the customers in the boutique. At the time of a customer login or new customer, it is used to check if the customer with this ID already exists or not.
2. Function to create a new customer account
The customer account function asks customers to enter their customer ID and it checks if a customer with this ID already exists or not because customer ID is a primary key in the customer table in the database and the values entered in these columns must be unique. If the customer exists it displays a message, else it takes the customer’s details and inserts the record in the customer table of the database.
3. Get booked products function
This function returns a list of products booked by a customer using the customer’s ID. It is used in other functions to view or delete the booked orders of the customer.
4. Function for Customer Login
This function allows the customer to log in to their accounts. It first checks if a customer with entered ID exists or not, and then asks for the customer’s choice to :
- View their booked products
- To view the products booked by customers, the get booked product function is used where customer ID is passed as an argument.
- It then checks if the customer has any bookings or not and then displays the result accordingly.
- If more than one product is booked, the product IDs are stored as a single value in the table separated by ‘_’. The fetched values are then split and printed.
- Book a new product
- To book a new product, the function asks the customer to enter the product ID and then checks if the product with the given ID exists in the products table or not. It then adds the product to the booked products column of the customer’s table.
- If the customer already has a booked product, the new product ID is concatenated with the existing ID and again stored in the table.
- Update their existing details
- For the customer to update their account, the function displays the existing customer details and then asks them to enter the fields they want to update.
- Cancel booked products
- To cancel booked products the function asks for product ID and checks if it is booked or not and then deletes it accordingly.
5. View Products function
This function fetches all existing products from the database and then displays them in the form of a table.
6. Add Products Function
Add products function is used by the employees of the boutique to add new product details. It asks for a product number, product ID, price, and stock from the employee and enters a new record in the products table of the database.
7. Delete Product Function
This function is used by the employees of the boutique to delete product details. It asks for the product ID and then deletes the record from the products table of the database.
8. Function for employee login
This function is used for employees to login into their accounts. It allows employees to :
- Update the records of delivered products.
- Add a new product to the database
- Deletes a product from the database
10. Add Employee Function
Add employee function allows the employer to add a new employee to the boutique and insert the records into the employee table of the database.
11. Function for employer login
This function is used for employer login and allows the employer to :
- View all products
- Add a new employee
The program first asks for a choice of the user to enter as a customer, employee, or employer and calls the respective functions for the functioning of the program.
Let’s view the records added to the database.
Records in the Tables after executing the program: