0
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!

asked Mar 6, 2012 at 13:16

2 Answers 2

3

You forgot the space after INFILE and before INTO. Also make sure to sanitize infilename or risk SQL injections.

answered Mar 6, 2012 at 13:19
Sign up to request clarification or add additional context in comments.

Comments

1

should be like this:

insertQuery = "LOAD DATA LOCAL INFILE " + infilename + " INTO TABLE vlan_area 
(vlan_id, area)" 
answered Mar 6, 2012 at 13:24

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.