also, would like to know of a way to have the 1000 to have the ability to look at the end of the row and then look at the next row of data, because there are sometimes +/-1000 characters in a row.
can someone please assist?
many thanks.
Code: Select all
<?php
//connect
to the database
include "opendb.php";
#if the first row of csv file contains column headings:
$columnheadings = 1;
if (($handle = fopen("/my/file
/destination/name.csv", "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$num = count($data);
# echo "<p> $num fields in line $columnheadings: <br /></p>\n";
$columnheadings++;
for ($i=0; $i<$num; $i++)
{
$line = trim($data[$i],'",');
$arr = explode(',',$line);
//mysql insert of values
$sqlData = ("INSERT INTO thisTable(name1, name2, name3, name4, name5) VALUES('".$arr[0]."', '".$arr[1]."', '".$arr[2]."', '".$arr[3]."', '".$arr[4]."')");
}
}
fclose($handle);
}
else
{
mysql_query($sqlData) or
die(mysql_error("The specified file does not exist. Thanks."));
}
mysql_close($con);
?>