Forum Moderators: open
If there is no value it can't write an empty string to that field.... if it is indeed a integer field.
Some code to check for it and insert an allowable value should do it.
if (numeric_field.trim() == ""){
numeric_field = 0
}
or
if (numeric_field.trim() == ""){
numeric_field = null
}
If this isn't the problem post back with more info as to how you are importing this file and other such details.. are you getting an error? Does the file just not import? do only parts of it import?
Secondly, yes, I am able to import the records that dont have empty fields in numeric columns.
I used a script that I found on MySQL website for importing.
$fcontents = file ('file.csv');
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i], ',');
$arr = explode(",", $line);
#if your data is comma separated
# instead of tab separated,
# change the '\t' above to ','
$sql = "insert into table values ('".
implode("','", $arr) ."')";
mysql_query($sql);
echo $sql ."<br>\n";
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
}
?>