好的,我将从我的代码开始:
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
循环内的 ing 证明了这一点。我在这里哪里出错了?