OK I'll start with my code:
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);
This fails to insert the data into the database table, although it does result in a load of blank rows being inserted.
The csv data is being correctly read as evidenced by the echo
ing of it inside the loop. Where have I gone wrong here?