manton Posted May 6, 2007 Share Posted May 6, 2007 Hi I want to use a variable inside to a sql query here is an example $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 advanced Link to comment https://forums.phpfreaks.com/topic/50227-mysql-command/ Share on other sites More sharing options...
Barand Posted May 6, 2007 Share Posted May 6, 2007 If the file is on the server, remove LOCAL Link to comment https://forums.phpfreaks.com/topic/50227-mysql-command/#findComment-246554 Share on other sites More sharing options...
manton Posted May 6, 2007 Author Share Posted May 6, 2007 I did what you say but i get the same error "Parse error: syntax error, unexpected T_VARIABLE in D:\webroot\assembly\insert.php on line 43" Link to comment https://forums.phpfreaks.com/topic/50227-mysql-command/#findComment-246555 Share on other sites More sharing options...
Barand Posted May 6, 2007 Share Posted May 6, 2007 For varuable values to be expanded, the string's outer quotes need to be double-quotes try <?php $var = $_SERVER['DOCUMENT_ROOT']."/files/data.csv"; $sql = "LOAD DATA INFILE '$var' INTO TABLE `data` FIELDS TERMINATED BY ';' ENCLOSED BY '\"' ESCAPED BY '\\\\' LINES TERMINATED BY '\r\n' "; ?> Link to comment https://forums.phpfreaks.com/topic/50227-mysql-command/#findComment-246559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.