Interface With Python
Interface With Python
Revision Worksheet
Interface Python with MySql
Subject: Computer Science
1 Identify the name of connector to establish bridge between Python and MySQL
a. mysql.connection
b. connector
c. mysql.connect
d. mysql.connector
2 Which function of connection is used to check whether connection to mysql is
successfullydone or not?
import mysql.connector as msq
con = msq.connect( #Connection String ) # Assuming all parameter required
as passedif :
print(“Connected!”)
else:
print(“ Error! Not Connected”)
a. con.connected()
b. con.isconnected()
c. con.is_connected()
d. con.is_connect()
3 Identify the correct statement to create cursor:
import mysql.connector as msq
con = msq.connect( #Connection String ) # Assuming all parameter required
as passedmycursor =
a. con.cursor()
b. con.create_cursor()
c. con.open_cursor()
d. con.get_cursor()
4 What is the difference in fetchall() and fetchone()?
a. mycursor.count
b. mycursor.row_count
c. mycursor.records
d. mycursor.rowcount
6 The code given below reads the following record from the table named student and displays only
those records who have marks greater than 75:
RollNo – integer
Name – string
Class – integer
Marks – integer
Note the following to establish connectivity between Python and MYSQL:
• Username is root
• Password is tiger
• The table exists in a MYSQL database named school. Write the following missing statements to
complete the code: Statement 1 – to form the cursor object Statement 2 – to execute the query
that extracts records of those students whose marks are greater than 75. Statement 3- to read
the complete result of the query (records whose marks are greater than 75) into the object
named data, from the table student in the database.