0% found this document useful (0 votes)
6 views2 pages

Python With Mysql

Uploaded by

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

Python With Mysql

Uploaded by

Sparsh Bhatia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import mysql.

connector as con
db=[Link](host='localhost',user='root',password='a
dmin',database='class12')
cursor=[Link]()
[Link]("select * from club")
data=[Link](5)
for i in data:
print(i)

[Link]()

OLD STYLE (for numeric value)

import [Link] as con


db=[Link](host='localhost',user='root',password='a
dmin',database='class12')
cursor=[Link]()
x=int(input("Enter Age "))
[Link]("select * from club where age<%s"%(x,))
data=[Link](5)
for i in data:
print(i)

[Link]()

OLD STYLE (for string value)

import [Link] as con


db=[Link](host='localhost',user='root',password='a
dmin',database='class12')
cursor=[Link]()
x=input("Enter sports ")
[Link]("select * from club where
sports='%s'"%(x,))
data=[Link]()
for i in data:
print(i)

[Link]()
new STYLE (for numeric value)

import [Link] as con


db=[Link](host='localhost',user='root',password='a
dmin',database='class12')
cursor=[Link]()
x=int(input("Enter Age "))
[Link]("select * from club where
age<{}".format(x,))
data=[Link](5)
for i in data:
print(i)

[Link]()

NEW STYLE (for string value)

import [Link] as con


db=[Link](host='localhost',user='root',password='a
dmin',database='class12')
cursor=[Link]()
x=input("Enter sports ")
[Link]("select * from club where
sports='{}".format(x,))
data=[Link]()
for i in data:
print(i)

[Link]()

COMMIT()

import [Link] as con


db=[Link](host='localhost',user='root',password='a
dmin',database='class12')
cursor=[Link]()
[Link]("delete from club where coach_id=1")
[Link]()
[Link]()

You might also like