好的,我将从我的代码开始:
include('connect.php');
// Prepared statement, prepare
if (!($stmt = $mysqli->prepare("INSERT INTO funddata(ticker, priceDate, price) VALUES (?, ?, ?)"))) {
echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
//Bind the parameters to the query
$csvData = array("","",""); //Initialise the $csvData array
$priceDate = date($csvData[1]);
$stmt -> bind_param("ssd", $csvData[0], $priceDate, $csvData[2]);
$file_handle = fopen($csvfile, "r");
while (!feof($file_handle) ) {
$csvData = fgetcsv($file_handle, 1024);
$priceDate = date($csvData[1]);
echo $csvData[0] . "; " . $priceDate . "; ". $csvData[2] . "<br/>";
//Run the insert statement
$stmt->execute();
}
fclose($file_handle);
这无法将数据插入到数据库表中,尽管它确实会导致插入大量空白行。
正在读取csv数据,正如循环内echo
所证明的那样。
我在哪里错了?