Skip to content Skip to sidebar Skip to footer

Importing Csv File With Null Values Into Phpmyadmin

When I import a csv file into MySQL (phpmyadmin), for all integer values that are not specified in the file but have a default of null there is an error message: #1366 - Incorrect

Solution 1:

CSV has no concept of "Nulls". It's impossible to differentiate between a field that is null, and a field that has a legitimately empty value (e.g. empty string). You'll have to massage the rows as you load them prior to query insertion, to replace any 'empty strings' with appropriate NULLs

e.g.

$row = fgetcsv(...);
$row[0] = 'NULL';

Post a Comment for "Importing Csv File With Null Values Into Phpmyadmin"