0

I am getting the following error while inserting data from CSV:

SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'Number' at row 1

My Database:

enter image description here

My CSV File:

enter image description here

My Codes:

$user = new USER();

$file = "test.csv";
 $handle = fopen($file, "r");
 $c = 0;
 while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
 {
 $name = $filesop[0];
 $user->new_number($name);
 }
user10670473
  • 65
  • 1
  • 8
  • You have no values in your number column? Aside: are `INT(255)` and `INT(15)` actually valid data types? Normally it's `INT(11) signed` or `INT(10) unsigned`... – CD001 Jul 04 '19 at 10:01
  • 1
    Well the number in parenthesis does not affect storage of the number. It is simply used to indicate the display width. See: https://stackoverflow.com/questions/3135804/types-in-mysql-bigint20-vs-int20. The number you are adding should be a valid integer. Try to convert the number to integer using (int) $variable – Nadir Latif Jul 04 '19 at 10:05
  • You mean `$name = $filesop[0]; $name = (int)$name;` @NadirLatif – user10670473 Jul 04 '19 at 10:07
  • If so, all numbers are converted to ***2147483647***. @NadirLatif – user10670473 Jul 04 '19 at 10:11
  • @NadirLatif - yes, but since the largest value that can be held in an (unsigned) `INT` is ~4.2 billion - a 10 digit number - that means that `INT(15)` and `INT(255)` would still be invalid, no? Hence `INT(10) unsigned` and `INT(11) signed` (as it has +/-). – CD001 Jul 04 '19 at 10:12
  • 1
    Well MySQL stores integers in 32 bits. Which means it can only store values between -2147483648 and 2147483647. If the column is configured as unsigned, then the range is 0 - 4294967295. In both cases whether we use signed or unsigned it will not be enough to store a number like 9955445599. So the type of the column should be changed from int to bigint. See https://stackoverflow.com/questions/6921613/mysql-int11-number-out-of-range and also https://dev.mysql.com/doc/refman/8.0/en/numeric-type-overview.html – Nadir Latif Jul 04 '19 at 11:23
  • It means to store mobile numbers we should use `bigint`? – user10670473 Jul 04 '19 at 11:26

0 Answers0