Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter keeps inserting 2147483647 for int values

Each time i try storing the id 1008218499200959 or any other 'long' int value to the database it's stored as 2147483647 and i have the data length set to 20 so the length shouldn't have been the problem i guess.

Is this a CodeIgniter or database issue?

I later fixed it by changing the data type to varchar but i'll still like to know why it behaves that way. Thank you.

-- Table structure for table applicants

CREATE TABLE IF NOT EXISTS `applicants` (
  `id` int(20) NOT NULL,
  `first_name` varchar(20) NOT NULL,
  `last_name` varchar(30) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;`
like image 994
Victor Anuebunwa Avatar asked Jul 10 '26 05:07

Victor Anuebunwa


1 Answers

The problem is with MySQL based on the id type you have defined. The largest int value is 2147483647. Check out their docs: https://dev.mysql.com/doc/refman/5.5/en/integer-types.html

Other options:

  • Signed BIGINT can get you to 9223372036854775807
  • Unsigned BIGINT can get you to 18446744073709551615
  • The maximum number of digits for DECIMAL is 65

(see https://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html for more details).

like image 150
Ann Addicks Avatar answered Jul 11 '26 21:07

Ann Addicks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!