CBSE Class 12 Computer Science
Question 45 of 46
Interface Python with MySQL — Question 2
Back to all questionsimport mysql.connector
db_con = mysql.connector.connect(host = "localhost",
user = "root",
passwd = "lion",
database = "menagerie")
cursor = db_con.cursor()
cursor.execute("SELECT * FROM event WHERE type = 'kennel'")
records = cursor.fetchall()
for record in records:
print(record)
db_con.close()('Bowser', datetime.date(1991, 10, 12), 'kennel', None)
('Fang', datetime.date(1991, 10, 12), 'kennel', None)