'I am getting an operational error while trying to call out a function in python . It is showing that the connection with Mysql server was lost
def add_book(self):
print('\nEnter 1 if want to add academic book or 2 for a non academic book')
check = int(input('Enter your choice: '))
if check == 1:
Book_name = input('Enter the Book Name: ')
con = db.connect(user='root', password='', host='localhost', database='readers joint')
cursor = con.cursor()
query = '''SELECT BookName,Category,Status,Borrowing_ID,SName,SEmail FROM academic where BookName = '%s' '''
cursor.execute(query% Book_name)
detail = cursor.fetchall()
if len(detail) > 0:
print(Book_name," already exists ")
con.close
else:
cat=input("Enter subject: \nPhysics\nChemistry\nBiology\nMaths\n ")
con = db.connect(user='root', password='', host='localhost', database='readers joint')
cursor = con.cursor()
query="INSERT INTO academic(BookName,Category,Status,Borrowing_ID,SName,SEmail) VALUES(%s,%s,%s,%s,%s,%s)",(Book_name,cat,'Available','','','')
cursor.execute(query)
con.commit
print(Book_name," has been added")
con.close
else:
print("Wrong input")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
