Parameterizing file name in MYSQL LOAD DATA INFILE

Ameya picture Ameya · May 14, 2010 · Viewed 9.8k times · Source

Is there a way to dynamically specify a file name in the LOAD DATA INFILE? Can it be parameterized like for instance (syntax may be incorrect) LOAD DATA INFILE '$filename'?

Answer

newtover picture newtover · May 14, 2010

A citation from MySQL documentation:

The LOAD DATA INFILE statement reads rows from a text file into a table at a very high speed. The file name must be given as a literal string.

That means that it can not be a parameter of a prepared statement. But no one forbids to make the string interpolation while the statement is just a string in your PHP code.