You should be able to test against the empty records with field=='' or using the empty function, so putting the insert function in an if should avoid empty records being inserted into the DB.
Untested
//open file read only
$file=fopen("test.csv","r");
while (!feof($file))
{
$row=fgetcsv("test.csv",0); //explode can be used instead
if (!empty($row[0])) // checks only the first field, add OR !emptry($row[1]) to include the other fields
{
$sql=sprintf("INSERT INTO table (field1, field2, field3) VALUES ('%s','%s','%s')",$row[0], $row[1], $row[2]); //use %d if the values are numbers instead of a string/text
mysql_query($sql)||die("Insert error: ".mysql_error());
}
}
//close file
fclose($file);