1.
Write a programme in Python based on the following database and table to connect to
MySQL and display details of patients.
Database name : ******* ( your database name )
Table name : hospital
import [Link] as p
q=[Link](host=’localhost’,user=’root’,passwd=’tiger’,database=’**********’)
if q.is_connected()==True:
print(‘Connection successful…..’)
else:
print(‘Connection unsuccessful…..’)
r=[Link]()
[Link](“select * from hospital”)
data=[Link]()
for i in data:
print(i)
2. Write a programme in Python based on the following database and table to connect to
MySQL and insert details of patients.
Database name : ******* ( your database name )
Table name : hospital
import [Link] as p
q=[Link](host=’localhost’,user=’root’,passwd=’tiger’,database=’**********’)
if q.is_connected()==True:
print(‘Connection successful…..’)
else:
print(‘Connection unsuccessful…..’)
r=[Link]()
s=”insert into hospital values({},’{}’,’{}’,’{}’,{}”.format(321,’Jonathan
Pat’,’ENT’,’Male’,32)
[Link](s)
[Link]()
3. Write a programme in Python based on the following database and table to connect to
MySQL and change department from cardio to neuro whose patient id is 326 .
Database name : ******* ( your database name )
Table name : hospital
import [Link] as p
q=[Link](host=’localhost’,user=’root’,passwd=’tiger’,database=’**********’)
if q.is_connected()==True:
print(‘Connection successful…..’)
else:
print(‘Connection unsuccessful…..’)
r=[Link]()
s=”update hospital set dept=’{}’ where pid={}”.format(‘cardio’,’neuro’,326)
[Link](s)
[Link]()
4. Write a programme in Python based on the following database and table to connect to
MySQL and display details of patients whose age and department is given by the user
.
Database name : ******* ( your database name )
Table name : hospital
import [Link] as p
q=[Link](host=’localhost’,user=’root’,passwd=’tiger’,database=’**********’)
if q.is_connected()==True:
print(‘Connection successful…..’)
else:
print(‘Connection unsuccessful…..’)
r=[Link]()
x=int(input(‘Enter age of the patient :’))
y=input(‘Enter department of the patient :’))
s=”select * from hospital where age={} and dept=’{}’”.format(x,y)
data=[Link](s)
for i in data:
print(i)