Reputation: 3305
def get(infilename):
fd_in = open(infilename, "r")
try:
con = mdb.connect (host=MY_HOST, user=MY_USER, passwd=MY_PASS, db=MY_DB)
cur = con.cursor()
insertQuery = "LOAD DATA LOCAL INFILE" + infilename + "INTO TABLE vlan_area (vlan_id, area)"
In python, I want to import a txt file to Mysql database, I want to get the file name dynamically, but this inserQuery is wrong, I don't know how to write it, can anyone help? many thanks!
Upvotes: 0
Views: 314
Reputation: 77856
should be like this:
insertQuery = "LOAD DATA LOCAL INFILE " + infilename + " INTO TABLE vlan_area
(vlan_id, area)"
Upvotes: 1
Reputation: 11381
You forgot the space after INFILE
and before INTO
. Also make sure to sanitize infilename
or risk SQL injections.
Upvotes: 3