import mysql.connector
mydb = mysql.connector.connect(host="localhost", user="", passwd="", db="world")
cursor = mydb.cursor()
file = open('C:\\test\\File.txt', 'w')
file_content = file.write()
query = "SELECT * FROM city where name='kabul'"
cursor.execute(query, (file_content,))
mydb.commit()
mydb.close()
Here i'm storing the data in text file but error
name 'file_content' is not defined
file.read(), seeing as write expects a parameter of data to write. And you probably wantopen('...', 'r')and not'w'seeing as that overwrites the file, rather than opening it for data-reading.file.read. Although, the query has no paramters so it makes no sense as well. Please clarify.