Python Select Dynamic

Estimated reading: 1 minute 335 views

Python Select dynamic Operation.

we need to use placeholder.

With MYSqLdb, you should use a placeholder of %s to format all the data value as string.

MYSQL will perform type conversion as necessery.

				
					import pymysql


conn = pymysql.connect(
        host='localhost',
        user='root',
        password="12345",
        db='sakila',
)

cur = conn.cursor()

get_id = int(input("enter the id"))

q1 = "select * from student where id = %s"

cur.execute(q1,get_id)

output = cur.fetchall()
print(output)
				
			

Leave a Comment

CONTENTS