Interfacing SQL with Python

 

import mysql.connector as cn

print("==============Program to display records on screen==============")

con=cn.connect(host='localhost',user='root',password='root',database='emp_db')

if con.is_connected():

    print("connected to the database....")

cr=con.cursor()

#cr.execute("create table empdemo(e_id varchar(20),ename varchar(20));")

cr.execute("select * from emp")

data=cr.fetchall()

for rec in data:

   print(rec)

Comments

Popular posts from this blog

Binary file update using Python program