Jump to content

using LOAD DATA LOCAL INFILE and also adding user id


antonyfal

Recommended Posts

Hi..

I have some code that uses the "LOAD DATA LOCAL INFILE" function, the full function works flawlessly. However i use it as a front-end public function for users to import their .csv data into a mysql database.. The function makes use of data mapping to the database.

 

I would like to also set additional cell data to the table to each row added from the "LOAD DATA LOCAL INFILE" function.. IE: the users site id..

 

HERE IS MY CODE:

 

<pre>

      $sql = "LOAD DATA LOCAL INFILE '".@mysql_escape_string($this->file_name).
             "' IGNORE INTO TABLE `".$this->table_name.
             "` FIELDS TERMINATED BY '".@mysql_escape_string($this->field_separate_char).
             "' OPTIONALLY ENCLOSED BY '".@mysql_escape_string($this->field_enclose_char).
             "' ESCAPED BY '".@mysql_escape_string($this->field_escape_char).
             "' LINES TERMINATED BY '". $this->line_separate_char .
             "' ".
             ($this->use_csv_header ? " IGNORE 1 LINES " : "")
             ."(".implode(",", $fields).") SET `prop_userid` = '".$thisJRuser->id."',`property_uid` = '".$defaultProperty."',`dateadd` = '".CURRENT_TIMESTAMP"'";           

</pre>

 

im having problems from this line:

<pre>

SET `prop_userid` = '".$thisNuser->id."',`property_uid` = '".$defaultProfile."',`dateadd` = '".CURRENT_TIMESTAMP"'";        

</pre>

 

could someone show me the correct way to right this last line in..

 

here is original working code without the SET columns:

 

<pre>

      $sql = "LOAD DATA LOCAL INFILE '".@mysql_escape_string($this->file_name).
             "' IGNORE INTO TABLE `".$this->table_name.
             "` FIELDS TERMINATED BY '".@mysql_escape_string($this->field_separate_char).
             "' OPTIONALLY ENCLOSED BY '".@mysql_escape_string($this->field_enclose_char).
             "' ESCAPED BY '".@mysql_escape_string($this->field_escape_char).
             "' LINES TERMINATED BY '". $this->line_separate_char .
             "' ".
             ($this->use_csv_header ? " IGNORE 1 LINES " : "")
             ."(".implode(",", $fields).")";

</pre>

 

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.