mysql command

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manton
Forum Newbie
Posts: 10
Joined: Fri Apr 27, 2007 8:27 am
Location: Athens

mysql command

Post by manton »

Hi

I want to use a variable inside to a sql query, here is an example

Code: Select all

$var = $_SERVER['DOCUMENT_ROOT']."/files/data.csv";
$sql = 'LOAD DATA LOCAL INFILE \"'$var'\" INTO TABLE `data` FIELDS TERMINATED BY \';\' ENCLOSED BY \'"\' ESCAPED BY \'\\\\\' LINES TERMINATED BY \'\\r\\n\'';
mysql_query($sql, $palso) or die(mysql_error());
What am i doing wrong?

thanks in advance :D
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Variable substituion doesn't take place in single-quoted strings.

Code: Select all

$var = 1234;
echo ' a: $var ';
echo " b: $var ";
prints
a: $var b: 1234
Post Reply