Python MySQL Update Table

How To Update The Selected Row In MySQL Database Table Using Python

Python MySQL Update Table


import mysql.connector

connection = mysql.connector.connect(
host='localhost',
user='root', password='',
port='3306',
database='test_py'
)
c = connection.cursor()

def updateData():
update_query = """UPDATE `users_2` SET
`firstname`=%s,`lastname`=%s,
`email`=%s,`age`=%s
WHERE `id` =%s """

vals = ("NewFName","NewLName","NewEmail@gmail.com",56,5)

c.execute(update_query,vals)

connection.commit()


updateData()


OUTPUT:

Python MySQL Update - Before Updating
Python MySQL Update - Before Updating

Python MySQL Update - Before Updating
Python MySQL Update - After Updating





Share this

Related Posts

Previous
Next Post »