使用Johnboy's tutorial将.csv文件导入MySQL时,我尝试制作一个可以从雅虎财务中获取汇率数据的脚本,并将其写入MySQL数据库。
<?php
//connect to the database
$host = "****"
$user = "****"
$password = "****"
$database = "****"
$connect = mysql_connect($host,$user,$password);
mysql_select_db($database,$connect);
//select the table
if ($_FILES[csv][size] > 0) {
//get the csv file
$symbol = "ZARINR"
$tag = "l1"
$file = "http://finance.yahoo.com/d/quotes.csv?e=.csv&f=$tag&s='$symbol'=x";
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do {
if ($data[0]) {
mysql_query("INSERT INTO ZAR_to_INR(exchange_rate) VALUES
(
'".addslashes($data[0])."',
)
");
echo "done";
}
} while ($data = fgetcsv($handle,1000,",","'"));
//redirect
header('Location: import.php?success=1'); die;
}
else{
echo "nope";
}
?>
我添加了回声,希望他们能告诉我脚本是否有效。它根本不起作用。没有错误消息或任何内容。当我通过在我的webhost中打开它来运行脚本时,它根本就不会运行。
我很感激有关如何使这个脚本工作的任何建议(甚至是解决问题的另一种方法)。
答案 0 :(得分:1)
尝试使用mysql调试:
mysql_select_db($database) or die('Cant connect to database');
$result = mysql_query($query) or die('query fail : ' . mysql_error());
$connect = mysql_connect($host,$user,$password)
or die('Cant connect to server: ' . mysql_error());
要查找此输出,您需要检查您的php error_log:where-does-php-store-the-error-log