I am trying to take a rather large CSV file and insert it into a MySQL database for referencing in a project. I would like to use the first line of the file to create the ta
Try casting the value and comparing it with the original one:
define('DECIMAL_SEPARATOR', '.');
switch ($fieldList[$i])
{
case (string)(int)$fieldList[$i]:
$typeInfo = (strpos($fieldList[$i], DECIMAL_SEPARATOR) === false) ? 'int(11)' : 'float';
break;
case (string)(float)$fieldList[$i]:
$typeInfo = 'float';
break;
default:
$typeInfo = 'varchar(80)';
break;
}
Additionaly, check for the presence of decimal separator in the first case for numbers that are round, yet they have the decimal fraction part.