FOPEN and FGETCSV to import CSV values...

Hi,
I’m using FOPEN and FGETCSV functions to import a CSV file into SQL Server.
I have found that whenever any of the columns have a blank/null value, that particular row is not being imported into the table.
HOW CAN I HAVE ALL RAWS IMPORTED, EVEN IF THEY HAVE BLANK/NULL VALUES?
I WILL TRULY APPRECIATE YOUR HELP.
Below the code I’m using:
/******************************************************************/
if (($handle = fopen(“uploads/TestFile.csv”, “r”)) !== FALSE) {
while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE) {
$num = count($data);
for ($c=0; $c < $num; $c++) {
$col[$c] = $data[$c];
}

$col1 = $col[0];
$col2 = $col[1];
$col3 = $col[2];
$IntegrateData = “INSERT INTO TestTable
VALUES (”. $col1.",".$col2.",".$col3.")";
$statement = $conn->prepare($IntegrateData);
$statement->execute();
}
fclose($handle);
}

Sponsor our Newsletter | Privacy Policy | Terms of Service