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

mysql interface

Uploaded by

KASHISH MADAN
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

mysql interface

Uploaded by

KASHISH MADAN
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

MYSQL INTERFACE

SELECTION USING PYTHON SQL


CONNECTOR-
import mysql.connector as sqlcon
mycon=sqlcon.connect(host='localhost',user='root',passwd='
kashishmadan14',database='kashish')
if mycon.is_connected():
print('Sucessfully Connected to MYSQL Database')
mycursor=mycon.cursor()
mycursor.execute("select * from MEMBER")
for data in mycursor:
print(data)
INSERTION USING PYTHON SQL
CONNECTOR-
import mysql.connector as sqlconn2
myconn=sqlconn2.connect(host='localhost',user='root',passw
d='kashishmadan14',database='kashish')
if myconn.is_connected()==False:
print('Erro connecting to MySQL')
Name=input("Enter name");
Date=input('DOB');
type=input('type');
remarks=input('Enter remarks')

mycursor=myconn.cursor()
mycursor.execute("insert into SALESPERSON
values('"+str(Name)+"','"+Date+"','"+type+"','"+remarks+"')")
myconn.commit()
DELETION USING PYTHON SQL
CONNECTOR-
import mysql.connector as sqlcon
mycon=sqlcon.connect(host='localhost',user='root
',passwd='kashishmadan14',database='kashish')
if mycon.is_connected():
print('Sucessfully Connected to MYSQL
Database')
mycursor=mycon.cursor()
mycursor.execute("drop SALESPERSON")
for data in mycursor:
print(data)
CREATION OF TABLE IN PYTHON SQL
CONNECTOR-
import mysql.connector as conn
mydb=conn.connect(host='localhost',user='root',passwd='kas
hishmadan14',database='kashish')
mycursor=mydb.cursor()
mycursor.execute('create table cust_data(cust_id integer
primary key, name varchar(25), gender varchar(1),DOB
date,Address varchar(20))');
mycursor.close()

You might also like