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>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.