I know to connect to a db and connected it and i done it by
import MySQLdb
db = MySQLdb.connect(host="localhost", # your host, usually localhost
user="root", # your username
passwd="mysql", # your password
db="sakila") # name of the data base
I have a text file qwer.txt i have the table name:vehicle
I need to perform the operation which is to print words that match the text file and database.my operation for a small db and small file is given by this but what about connecting the database and matching them?
mysql_row = "car,bike"
file_str = "I have a car"
mysql_elements = mysql_row.split(",")
file_elements = file_str.split(" ")
output_array = []
for m_element in mysql_elements:
for i in range(len(file_elements)):
if ((m_element == file_elements[i]) and (i < len(file_elements)-1)):
output_array.append(file_elements[i])
print output_array
Output:car
So,what are the changes to be done for connecting the database directly and the filename to perform the matching operation.