Grocery Store MGT System Computer Project

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

print("SHOP MANAGEMENT SYSTEM")

print("PYTHON MYSQL CONNECTIVITY")

import mysql.connector

import sys

while True:

print("MENU")

print("1-CREATE DATABASE\n2-SHOW DATABASE\n3-CREATE TABLE\n4-SHOW TABLES")

print("5-DESC TABLE\n6-SEARCH AND DISPLAY\n7-SELECT QUERY\n8-WHERE CLAUSE")

print("9-INSERT DYNAMICALLY\n10-UPDATE RECORDS \n11-DELETE RECORDS\n12-EXIT\n")

ch=int(input("enter your choice"))

if ch==1:

mydb=mysql.connector.connect(host="localhost", user="root", passwd="amalanto20")

mycursor=mydb.cursor()

mycursor.execute("CREATE DATABASE SHOP")

print("DATABASE CREATED")

if ch==2:

mydb=mysql.connector.connect(host="localhost", user="root", passwd="amalanto20")

mycursor=mydb.cursor()

mycursor.execute("SHOW DATABASES")

for x in mycursor:

print(x)

if ch==3:

mydb=mysql.connector.connect(host="localhost", user="root", passwd="amalanto20",


database="SHOP")

mycursor=mydb.cursor()

mycursor.execute("CREATE TABLE SHOP (ITEMNO INTEGER(3), NAME VARCHAR(20), AMOUNT


INTEGER(10))");

print("TABLE CREATED")

if ch==4:

mydb=mysql.connector.connect(host="localhost", user="root", passwd="amalanto20",


database="SHOP")

mycursor=mydb.cursor()
mycursor.execute("SHOW TABLES")

for x in mycursor:

print(x)

if ch==5:

mydb=mysql.connector.connect(host="localhost", user="root", passwd="amalanto20",


database="SHOP")

mycursor=mydb.cursor()

mycursor.execute("DESC SHOP")

for x in mycursor:

print(x)

if ch==6:

mydb=mysql.connector.connect(host="localhost",user="root", passwd="amalanto20",
database="SHOP")

if mydb.is_connected() ==True:

print("connection ok")

else:

print("error connecting to mysql database")

mycursor=mydb.cursor()

mycursor.execute("SELECT * FROM SHOP")

rs=mycursor.fetchall()

n=input("enter name to search")

for row in rs:

if row[1]==n:

print (row)

if ch==7:

conn=mysql.connector.connect(host="localhost", user="root", passwd="amalanto20",


database="SHOP")

c=conn.cursor()

c.execute("select * from SHOP")

r=c.fetchone()

while r is not None :

print(r)
r=c.fetchone()

if ch==8:

conn=mysql.connector.connect(host="localhost", user="root", passwd="amalanto20",


database="SHOP")

if conn.is_connected==False:

print("Error connecting to MYSQL DATABASE")

c=conn.cursor()

AMT=int(input("enter amount to search"))

c.execute("select * from SHOP where AMOUNT=AMT")

r=c.fetchall()

count=crowcount

print("total no of rows:", count)

for row in r:

print(row)

if ch==9:

mydb=mysql.connector.connect(host="localhost", user="root", passwd="amalanto20",


database="SHOP")

mycursor=mydb.cursor()

r=int(input("enter the ITEMno"))

n=input("enter name")

m=int(input("enter AMOUNT"))

mycursor.execute("INSERT INTO SHOP (ITEMNO, name, AMOUNT) VALUES('{},{},{}')")

mydb.commit()

print(mycursor.rowcount, "RECORD INSERTED ")

if ch==10:

mydb=mysql.connector.connect(host="localhost", user="root", passwd="amalanto20",


database="SHOP")

mycursor=mydb.cursor()

mycursor.execute("UPDATE SHOP SET AMOUNT=100 WHERE AMOUNT=40")

mydb.commit()

print(mycursor.rowcount,"RECORD UPDATED")

if ch==11:
mydb=mysql.connector.connect(host="localhost",user="root",passwd="amalanto20",
database="SHOP")

mycursor=mydb.cursor()

mycursor.execute("DELETE FROM SHOP WHERE AMOUNT=50")

mydb.commit()

print(mycursor.rowcount, "RECORD DELETED")

if ch==12:

sys.exit()

OUTPUT:

SHOP MANAGEMENT SYSTEM

PYTHON MYSQL CONNECTIVITY

MENU

1-CREATE DATABASE

2-SHOW DATABASE

3-CREATE TABLE

4-SHOW TABLES

5-DESC TABLE

6-SEARCH AND DISPLAY

7-SELECT QUERY

8-WHERE CLAUSE

9-INSERT DYNAMICALLY

10-UPDATE RECORDS

11-DELETE RECORDS

12-EXIT

enter your choice2

('information_schema',)

('grocery',)

('mysql',)

('performance_schema',)
('shop',)

('shopmanagement',)

('store',)

('supermarket',)

('sys',)

MENU

1-CREATE DATABASE

2-SHOW DATABASE

3-CREATE TABLE

4-SHOW TABLES

5-DESC TABLE

6-SEARCH AND DISPLAY

7-SELECT QUERY

8-WHERE CLAUSE

9-INSERT DYNAMICALLY

10-UPDATE RECORDS

11-DELETE RECORDS

12-EXIT

enter your choice4

('shop',)

MENU

1-CREATE DATABASE

2-SHOW DATABASE

3-CREATE TABLE

4-SHOW TABLES

5-DESC TABLE

6-SEARCH AND DISPLAY

7-SELECT QUERY

8-WHERE CLAUSE

9-INSERT DYNAMICALLY
10-UPDATE RECORDS

11-DELETE RECORDS

12-EXIT

enter your choice5

('ITEMNO', 'int(3)', 'YES', '', None, '')

('NAME', 'varchar(20)', 'YES', '', None, '')

('AMOUNT', 'int(10)', 'YES', '', None, '')

MENU

1-CREATE DATABASE

2-SHOW DATABASE

3-CREATE TABLE

4-SHOW TABLES

5-DESC TABLE

6-SEARCH AND DISPLAY

7-SELECT QUERY

8-WHERE CLAUSE

9-INSERT DYNAMICALLY

10-UPDATE RECORDS

11-DELETE RECORDS

12-EXIT

enter your choice6

connection ok

enter name to searchamal

MENU

1-CREATE DATABASE

2-SHOW DATABASE

3-CREATE TABLE

4-SHOW TABLES

5-DESC TABLE
6-SEARCH AND DISPLAY

7-SELECT QUERY

8-WHERE CLAUSE

9-INSERT DYNAMICALLY

10-UPDATE RECORDS

11-DELETE RECORDS

12-EXIT

enter your choice7

MENU

1-CREATE DATABASE

2-SHOW DATABASE

3-CREATE TABLE

4-SHOW TABLES

5-DESC TABLE

6-SEARCH AND DISPLAY

7-SELECT QUERY

8-WHERE CLAUSE

9-INSERT DYNAMICALLY

10-UPDATE RECORDS

11-DELETE RECORDS

12-EXIT

enter your choice10

0 RECORD UPDATED

MENU

1-CREATE DATABASE

2-SHOW DATABASE

3-CREATE TABLE

4-SHOW TABLES

5-DESC TABLE
6-SEARCH AND DISPLAY

7-SELECT QUERY

8-WHERE CLAUSE

9-INSERT DYNAMICALLY

10-UPDATE RECORDS

11-DELETE RECORDS

12-EXIT

enter your choice11

0 RECORD DELETED

MENU

1-CREATE DATABASE

2-SHOW DATABASE

3-CREATE TABLE

4-SHOW TABLES

5-DESC TABLE

6-SEARCH AND DISPLAY

7-SELECT QUERY

8-WHERE CLAUSE

9-INSERT DYNAMICALLY

10-UPDATE RECORDS

11-DELETE RECORDS

12-EXIT

enter your choice12

>>>

You might also like