必须使用php脚本导入mysql db表中的csv文件。csv文件如下:
"giorno","lmedollton","changedolleuro","euroton","lmesterton","delnotiz","girm","sgm"
"2016-09-02", "100.01", "4005.09", "5000", "1.09", "120.09", "100.5", "200.77"
"2016-09-03", "150.01", "4205.09", "5600", "1.10", "150.09", "300.5", "300.77"
表格结构如下:
# Campo Tipo Collation Attributi Null
1 id int(20) No Nessuno AUTO_INCREMENT
2 giorno date Sì NULL
3 lmedollton float Sì NULL
4 changedolleuro float Sì NULL
5 euroton float Sì NULL
6 lmesterton float Sì NULL
7 delnotiz float Sì NULL
8 girm float Sì NULL
9 sgm float Sì NULL
有两个问题:
1) 使用以下php代码:
$csvFile = "../scripts/tabella.csv";
$db = @mysql_connect('***', '***', '***');
@mysql_select_db('***');
$query = 'LOAD DATA LOCAL INFILE \' '. $csvFile .' \' INTO TABLE rame FIELDS TERMINATED BY \',\' ENCLOSED BY \'"\' LINES TERMINATED BY \'\n\'
(giorno,lmedollton,changedolleuro,euroton,lmesterton,delnotiz,girm,sgm)';
if(!mysql_query($query)){
die(mysql_error());
}
//@mysql_query($query);
mysql_close($db);
mysqlèerror返回'找不到文件';我也尝试过使用realpath函数,但是错误是一样的。csv文件位于中的站点服务器中www.valuebiz.it/valuebiz/scripts/tabella.csv 其权限为777。像url一样使用此路径,我可以正确下载tabella.csv。我应该用哪条路?
2) 我试图在localhost中运行查询,但添加的记录的每个字段都是空的。该表有9个字段,包括id字段(自动递增):第一个是日期类型,其他是浮点类型。为什么插入值为空?
你能帮帮我吗?谢谢!
暂无答案!
目前还没有任何答案,快来回答吧!