0% found this document useful (0 votes)
201 views2 pages

Interface With Python

This document provides a revision worksheet with questions about connecting Python to MySQL and performing basic operations. It includes questions about: 1. The MySQL connector module used to connect Python to MySQL. 2. Checking if a MySQL connection was successfully established. 3. Creating a cursor object to execute queries. 4. The difference between fetchall() and fetchone() cursor methods. 5. Getting the number of records in a cursor. 6. Writing code to query a database table and retrieve records where a condition is met. 7. The full steps to establish a database connection between Python and MySQL.

Uploaded by

Kishor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
201 views2 pages

Interface With Python

This document provides a revision worksheet with questions about connecting Python to MySQL and performing basic operations. It includes questions about: 1. The MySQL connector module used to connect Python to MySQL. 2. Checking if a MySQL connection was successfully established. 3. Creating a cursor object to execute queries. 4. The difference between fetchall() and fetchone() cursor methods. 5. Getting the number of records in a cursor. 6. Writing code to query a database table and retrieve records where a condition is met. 7. The full steps to establish a database connection between Python and MySQL.

Uploaded by

Kishor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

Kendriya Vidyalaya Sangathan, Ahmedabad Region

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()?

5 Which attribute of of cursor is used to get number of records stored in cursor


(Assumingcursor name is mycursor)?

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.

7 Write all the steps for creating database connectivity?

You might also like