0

how to escape this string

$sql = 'LOAD DATA LOCAL INFILE "C:\\xampp\\htdocs\\test\\import-excel\\book1.csv\\" INTO TABLE exam FIELDS TERMINATED BY  "," ';

because path to file will be a variable i don't know how to escape the path before use it in query , i used phpmyadmin ( create php code ) and it's gave me escaped string so i can use that , i hope someone can tell me about what function phpmyadmin use to generate this string from orginal string

$sql = "\'LOAD DATA LOCAL INFILE \"C:\\\\xampp\\\\htdocs\\\\test\\\\import-excel\\\\book1.csv\\\\\" INTO TABLE exam FIELDS TERMINATED BY \",\" \';";

tanks

1
  • What string? The one that starts with $sql? The one that starts with LOAD DATA? Or the one that starts with C:\\xampp? Commented Jan 8, 2011 at 18:17

1 Answer 1

1

http://php.net/manual/en/function.mysql-escape-string.php

Sign up to request clarification or add additional context in comments.

1 Comment

i have use it already but it's gave me this error : LOAD DATA LOCAL INFILE \"C:\\xampp\\htdocs\\test\\import-excel\\book1.csv\\\" INTO TABLE exam FIELDS TERMINATED BY \",\" Errormessage: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\"C:\\xampp\\htdocs\\test\\import-excel\\book1.csv\\\" INTO TABLE exam FIELDS TE' at line 1

Your Answer

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.