CH 8-Interfacing Python With Mysql (Connectivity) For Board Exam
CH 8-Interfacing Python With Mysql (Connectivity) For Board Exam
import mysql.connecotor as c
s=c.connect(host='localhost',user='a',password='a')
cur=c.cursor()
cur.execute('USE TRAVEL')
cur.execute("SELECT * FROM PASSENGERS")
Res=cur.fetchall()
for R in Res:
print(R[1])
s.close()
16. Consider the below given SCHOOL table and predict the
output of Python program based on this table:
17. Consider the below given LOCATION table and predict the
output of Python program based on this table:
password="1",database="stu")
if______________ # Statement 1
print("Error connecting to MYSQL DATABASE")
________________ # Statement 2
c.execute("select * from student where marks>80 and
marks<90")
_____________ # Statement 3
count=c.rowcount
print("total no of rows:",count)
for row in r:
print(row)
7. Consider the following Python code is written to access the
details of employee, whose employee number is given:
Complete the missing statements:
Statement 1 – To create a cursor object to execute the
query.
Statement 2 – To execute the query stored in the variable
change.
Statement 3 – To make the changes in the database
physically.
def Search():
import mysql.connector
mydb=mysql.connector.connect(host="localhost",
user="root",passwd="sys",database="DB")
_______________ # Statement 1
change="update employee set salary=salary+5000 where
empno= 1011"
_______________ # Statement 2
______________ # Statement 3
results = mycursor.fetchall()
print(results)
8. You are required to complete the statements so that the
code can be executed properly.
import mysql.connector
db=mysql.connector.________(i) fill the statement with
appropriate method.
(host='localhost',user='root',password='moahan')
cur=db.cursor( )
cur.execute("_______;") (ii) command to display all the
database name
print(cur.________) (iii) method to extract all the
required
from the cursor
9. You are required to complete the statements so that the
code can be executed properly.
import _______ (i) complete the statement with
appropriate library name
db=mysql.connector. __________(ii)
(host=”localhost”, user=”root”, password=”smsmb”)
(ii)-> # fill the statement with appropriate method
cur=db._________( ) (iii) # method to open the cursor
object
data= "______" (iv) #complete the statement with the
appropriate database name
cur.execute("________"+data) (v)
# command to open the
database
cur.execute("_____") (vi) #command to display name of all
the tables.
**********************************************************