How to load data to db from csv using LOAD DATA INFILE in drupal

瘦欲@ 提交于 2019-12-11 19:17:47

问题


I have tried the below code for laoding the inline file in drupal db

 $sql = "LOAD DATA INFILE '".db_escape_string($this->file_name).
         "' INTO TABLE `".$this->table_name.
         "` FIELDS TERMINATED BY '".db_escape_string($this->field_separate_char).
         "' OPTIONALLY ENCLOSED BY '".db_escape_string($this->field_enclose_char).
         "' ESCAPED BY '".db_escape_string($this->field_escape_char).
         "' ".
         ($this->use_csv_header ? " IGNORE 1 LINES " : "")
         ."(`".implode("`,`", $this->arr_csv_columns)."`)";
  $res = db_query($sql);
  $this->error = mysql_error();

I got the error as but the file was present in the folder

user warning: File 'http:\localhost\example\sites\default\files\example_1.csv' not found (Errcode: 22) query: LOAD DATA INFILE 'http://localhost/example/sites/default/files/example_1.csv' INTO TABLE temp_21_10_2010_06_38_00 FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\' IGNORE 1 LINES (PROGRAMNAME,OFFLINE,ONLINE,INSTOCK) in C:\wamp\www\example\sites\all\modules\importmodule\Quick_CSV_import.php on line 65.

On line 65 the above php code $res = db_query($sql); is present.


回答1:


you need to specify the full/absolute or a relative path to your csv file not a URL

load data infile '/myproj/imports/example_1.csv' into table...

load data infile 'c:\\myproj\\imports\\example_1.csv' into table...

suggest you check the manual again http://dev.mysql.com/doc/refman/5.1/en/load-data.html




回答2:


Perhaps is it due to open_files_limit ?



来源:https://stackoverflow.com/questions/3994133/how-to-load-data-to-db-from-csv-using-load-data-infile-in-drupal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!