0% found this document useful (0 votes)
6 views

( Record 15 ) Python mysql interface create and display[1]

Uploaded by

yohanmathew1906
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

( Record 15 ) Python mysql interface create and display[1]

Uploaded by

yohanmathew1906
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

#yohan – 12136

#Record program – 15
#Source Code
import mysql.connector as sql
con = sql.connect(host = 'localhost',user='root',password='admin',database='cvt11')
cur = con.cursor()
query = "create table if not exists hos (sno int, name varchar(15), age int, pid int, department varchar(20),
DOA date, charger int, gender char(1))"
cur.execute(query)
cur.execute('INSERT INTO hos VALUES (1, "April", 52, 123, "Surgery", "2015-01-21", 300, "m")')
cur.execute('INSERT INTO hos VALUES (2, "Bala", 49, 345, "Ortho", "2015-05-23", 250, "m")')
cur.execute('INSERT INTO hos VALUES (3, "Varshini", 40, 789, "Dentist", "2014-04-21", 300, "f")')
cur.execute('INSERT INTO hos VALUES (4, "Abhi", 45, 456, "Cardio", "2013-07-27", 300, "m")')
cur.execute('INSERT INTO hos VALUES (5, "Sunitha", 49, 657, "Pediatrician", "2015-09-21", 200,
"f")')

cur.execute('select*from hos')
rows = cur.fetchall()
for row in rows:
print(row)
con.close()

#yohan – 12136
#Record Program - 15
#Output
(1, 'April', 52, 123, 'Surgery', datetime.date(2015, 1, 21), 300, 'm')
(2, 'Bala', 49, 345, 'Ortho', datetime.date(2015, 5, 23), 250, 'm')
(3, 'Varshini', 40, 789, 'Dentist', datetime.date(2014, 4, 21), 300, 'f')
(4, 'Abhi', 45, 456, 'Cardio', datetime.date(2013, 7, 27), 300, 'm')
(5, 'Sunitha', 49, 657, 'Pediatrician', datetime.date(2015, 9, 21), 200, 'f')

You might also like