Analyze the following Python program that demonstrates connectivity between…
PYQ EMRS TGT/PGT (ESSE) 2025
Analyze the following Python program that demonstrates connectivity between Python and a MySQL database. The program is intended to insert a new record into a table named MYCONTACTS in the PHONEBOOK database. Some object and method names are missing from the code. Assume that an appropriate module for connectivity has been used and that it is functioning properly.
import mysql.connector as SQL # Line 01
MyDB = SQL._____(A)_____ (host='localhost', \
user='root', password='tiger', \
database='PHONEBOOK') # Line 02
MyCursor = MyDB._____(B)_____ () # Line 03
print('Enter the details of a row: ') # Line 04
Name = input('Enter Name: ') # Line 05
Phone = input('Enter Phone Number: ') # Line 06
Data = (Name, Phone) # Line 07
Command = "INSERT INTO MYCONTACTS VALUES(%s,%s);" # Line 08
MyCursor._____(C)_____ (Command, Data) # Line 09
_____(D)_____.commit() # Line 10(A) Write the name of the method/function in Line 02 required to establish database connectivity.
(B) Write the name of the method/function in Line 03 required to create the cursor object MyCursor.
(C) Write the name of the method/function in Line 09 required to execute the MySQL query successfully.
(D) Write the name of the object in Line 10 used to commit the changes (INSERT operation) successfully.
Attempted by 71 students.
Sign up free to check your answer
Sign up freeLoading lesson…

