Question: import mysql . connector import sys import time # Create a database connection def create _ connection ( ) : Create a
import mysqlconnector
import sys
import time
# Create a database connection
def createconnection:
Create a connection to 'zybooksdb' database
:return: Connection object
# YOUR CODE HERE
conn mysqlconnector.connect
user 'root',
host
database 'zybooksdb'
return conn
# Create Horse table
def createtableconn:
Create Horse table
:param conn: Connection object
:return: Nothing
cursor conn.cursor
# YOUR CODE HERE
cursor.executeDROP TABLE IF EXISTS Horse"
cursor.execute
CREATE TABLE Horse
ID INT PRIMARY KEY,
Nmae VARCHAR
Breed VARCHAR
Height DOUBLE,
BirthDatr VARCHAR
# Insert row to Horse table using paramenters
def inserthorseconn horsedata:
Create a new row in Horse table
:param conn: Connection object
:param data: Tuple of values to be inserted in row
:return: Nothing
# YOUR CODE HERE
cursor conn.cursor
insertquery
INSERT INTO Horse ID Name, Breed, Height, BirthDate
VALUES sssss
#horsedata 'Babe', 'Quarter Horse',
cursor.executeinsertquery, horsedata
conn.commit
# Select and print all rows of Horse table
def selectallhorsesconn:
Query all rows in the Horse table
:param conn: Connection object
:return: Nothing
# YOUR CODE HERE
cursor conn.CURSOR
cursor.executeselect FROM Horse"
rows cursor.fetchall
for row in rows:
Printrow
# DO NOT MODIFY main
if namemain:
# Create database connection
conn createconnection
if conn is None:
exit
# Create Horse table
createtableconn
# Insert row to Horse table
horsedata "Babe", "Quarter Horse",
inserthorseconn horsedata
# Select and print all Horse table rows
selectallhorsesconn
conn.close
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
