antonyfal Posted January 25, 2014 Share Posted January 25, 2014 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 https://forums.phpfreaks.com/topic/285672-using-load-data-local-infile-and-also-adding-user-id/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.