For some odd reason, some database values do not match the datastream. It is not for every entry although. For instance a line from my CSV file is below.
00-1751,P,1649.95,1649.95,1237.00
And somehow in my DB the same entry reads
00-1751,P,999.99,999.99,999.99
My code for dumping into the DB is below:
function dump($csvFile, $conn){
if(($handle = fopen($csvFile, 'r')) !== false) {
$header = fgetcsv($handle);
$id = 0;
$sql = "TRUNCATE TABLE inv_price";
$sth = $conn->prepare($sql);
$sth->execute();
while(($data = fgetcsv($handle)) !== false) {
$sql = "INSERT INTO `inv_price` (sku, part_status, msrp, curr_sugg_retail, your_price)
VALUES ('$id', '$data[0]', '$data[1]', '$data[2]', '$data[3]')";
print_r($data);
try{
$conn->query($sql);
}
catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
$id++;
}
fclose($handle);
}
}
The $data
printed to the console matches the CSV file. I am not sure how or why certain rows are changing the value to 999.99
.