CSC Project
CSC Project
RYAN
INTERNATIONAL
SCHOOL
INDEX
S no. TITLE
PAGE
3
1 CERTIFICATE
4
2 ACKNOWLEDGEMENT
5
3 OBJECTIVE
6
4 PYTHON CODE
13
5 OUTPUTS
3
CERTIFICATE
ACKNOWLEDGMENT
Objective
PYTHON CODE
import mysql.connector
import time
db = mysql.connector.connect(
host="localhost",
user="root",
password="1234",
database="contact"
)
cursor = db.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS book (
name char(30) primary key,
address char(100),
mobile char(15),
email char(30)
);
""")
def intro():
print("=" * 80)
print("{:^80s}".format("CONTACT"))
print("{:^80s}".format("BOOK"))
print("{:^80s}".format("PROJECT"))
7
print("{:^80s}".format("MADE BY:
PyForSchool.com"))
print("=" * 80)
print()
time.sleep(2)
def create_record():
name = input("Enter name: ")
address = input("Enter address: ")
mobile = input("Enter mobile: ")
email = input("Enter email: ")
sql = "INSERT INTO
book(name,address,mobile,email) VALUES (%s,
%s,%s,%s)"
record = (name, address, mobile, email)
cursor.execute(sql, record)
db.commit()
print("Record Entered Successfully\n")
def search(name):
sql = "SELECT * FROM book WHERE name =
%s"
value = (name,)
cursor.execute(sql, value)
record = cursor.fetchone()
if record is None:
print("No such record exists")
8
else:
print('Name:', record[0])
print('Address:', record[1])
print('Mobile:', record[2])
print('E-mail:', record[3])
def display_all():
cursor.execute("SELECT * FROM book")
print('{0:20}{1:30}{2:15}{3:30}'.format('NAME',
'ADDRESS', 'MOBILE NO', 'E-MAIL'))
for record in cursor:
print('{0:20}{1:30}{2:15}{3:30}'.format(record[0],
record[1], record[2], record[3]))
def delete_record(name):
sql = "DELETE FROM book WHERE name = %s"
value = (name,)
cursor.execute(sql, value)
db.commit()
if cursor.rowcount == 0:
print("Record not found")
else:
print("Record deleted successfully")
def modify_record(name):
9
def main():
intro()
while True:
print("\nMAIN MENU ")
print("1. ADD NEW RECORD")
print("2. SEARCH RECORD")
11
else:
print("Invalid choice")
main()
13
OUTPUTS
14