# download the file off the internet
$file = file_get_contents("http://localhost/sample.csv");
$filepath = "C:/xampp/htdocs/test/file/sample.csv";
file_put_contents($filepath, $file);
# load the data into sample table
$pt1 = "LOAD DATA LOCAL INFILE ";
$pt2 = "'/C:/xampp/htdocs/test/file/sample.csv' INTO TABLE sample ";
$pt3 = "FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ";
$pt4 = "LINES TERMINATED BY '\r\n' ";
$pt5 = "(col1,col2,col3,col4)";
$sqlquerynew = $pt1.$pt2.$pt3.$pt4.$pt5;
mysql_query($sqlquerynew);
这段代码适用于非 csv(好吧,我用文本文件对其进行了测试)。
在这部分运行之前,我必须创建一个表。现在已创建表,但未加载任何数据。路径中所述的文件存在。
可能是什么问题呢?
谢谢
这是我在网上找到的示例 csv
"REVIEW_DATE","AUTHOR","ISBN","DISCOUNTED_PRICE"
"1985/01/21","Douglas Adams",0345391802,5.95
"1990/01/12","Douglas Hofstadter",0465026567,9.95
....... etc