I am trying to allow users (In my place of work) to run a query, and if they choose, save it into a database so that they can just run it again later with a single click (Like if they are updating a database). I am having a problem with this, though. Simply running the query isn't an issue, but the query doesn't save correctly. The query is something like this:
LOAD DATA INFILE 'path/to/file/file.txt' INTO TABLE table FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n';
I can get it to save into the database correctly if I escape the backslashes when typing out the query, but that causes the query to run incorrectly on submit. I am wondering if there is a way that I can automatically escape backslashes. Or would it just be easier/better to separate the two features? If any more information is needed let me know, and thanks in advance.
mysqli_real_escape_sting()(or similar) or as suggested above use prepared statements to insert the record (thus avoiding the need to escape at all)?mysqli_real_escape_string(). I get this as a result: LOAD DATA INFILE \'path/to/file/file.txt\' INTO TABLE table FIELDS TERMINATED BY \' \' LINES TERMINATED BY \'\n\'; It keeps the \n, but still messes up the \t