Jump to content

mysql command


manton

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.