[Type B] Chapter 16 | Python application that fetches all the records from Pet table of Menagerie Database

Here is class 12 computer science Unit 16 solutions for Sumita Arora back exercise assignment. Below includes both textual and video solutions wherever required. View all the answers in assignment for chapter 16 and for all chapters here.

Sumita Arora Solutions for all lessons here.

Question 1: Design a Python application that fetches all the records from Pet table of menagerie database.
$ import mysql.connector as sql                              #import the sql package

$ obj = sql.connect(host="localhost", user="root", 
               passwd="Pass", database="menagerie")          #creating the object to database

$ cursor = obj.cursor()                                      #create a cursor object

$ cursor.execute("SELECT * FROM Pet ")                       #execute the query

$ data = cursor.fetchall()                                   #return all rows of result 

$ print(data)                                                # print all the rows

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

You cannot copy content of this page