如何在Drupal中使用LOAD DATA INFILE将数据从csv加载到db [英] How to load data to db from csv using LOAD DATA INFILE in drupal
问题描述
我已经尝试了以下代码在drupal db中对内联文件进行刷新
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
用户警告:找不到文件'http:\localhost\example\网站\默认\文件\example_1.csv'(错误代码:22)查询:LOAD DATA INFILE'http: //localhost/example/sites/default/files/example_1.csv'INTO TABLE temp_21_10_2010_06_38_00
字段以','可选,并以'\'代替I'IGNORE 1 LINES( PROGRAMNAME
, OFFLINE
, ONLINE
, INSTOCK
)在C:\wamp\www\example\sites\all\modules\importmodule\Quick_CSV_import.php行65.
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.
在第65行上,上述php代码 $ res = db_query($ sql);
存在。
On line 65 the above php code $res = db_query($sql);
is present.
推荐答案
您需要指定csv文件的完整/绝对或相对路径而不是URL
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...
建议您再次查看手册 http://dev.mysql.com/doc/refman/5.1/en/load-data .html
这篇关于如何在Drupal中使用LOAD DATA INFILE将数据从csv加载到db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!