Home:ALL Converter>How to use a dynamic variable in mysql query in python

How to use a dynamic variable in mysql query in python

Ask Time:2017-12-01T04:02:46         Author:kajol

Json Formatter

In my python code, I want to update the table value as per the user input so i need to pass the dynamic value in the query but i am not able to get any result. Can you suggest me way?

Below is my code:`

import mysql.connector

zone = # Dynamic value

rate = # Dynamic value

conn=mysql.connector.connect(user='root',password='1234',host='localhost',database='demo')


mycursor=conn.cursor()

mycursor.execute("UPDATE interest_rate SET interest=(rate,) where Bank_Name=%s",(zone,))

conn.commit()
`

How to pass the rate in the UPDATE query, I am able to pass the zone variable in the query. Can you help me to pass the rate variable?

I am using python 3.4 and MySQL as the database.

Author:kajol,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/47581682/how-to-use-a-dynamic-variable-in-mysql-query-in-python
yy