简体   繁体   English

数据上传显示数据库Codeigniter中的不同值

[英]data upload showing different value in database codeigniter

I have a form from where am getting the value to be saved into database. 我有一个表单,从那里获取要保存到数据库的值。 Running the insertion query it's inserting into database but the problem is the phone number saved looks like this number " 2147483647" though in the query am passing the number 9846586583. Every time I insert its saving this number. 运行插入查询,它正在插入数据库,但是问题是保存的电话号码看起来像这个数字“ 2147483647”,尽管在查询中传递的号码是9846586583。每次我插入它保存这个号码时。

The data types of the column for phone number i have set is int(16) . 我已设置的电话号码列的数据类型为int(16)

Below is the query that is displayed by <?php $this->output->enable_profiler(true);?> which shows a correct query 下面是<?php $this->output->enable_profiler(true);?>显示的查询,该查询显示了正确的查询

INSERT INTO `posts` (
    `country`,
    `city`,
    `area`,
    `street`,
    `house_no`,
    `house_type`,
    `floor`,
    `number_of_rooms`,
    `price`,
    `owners_phone`,
    `posted_by`,
    `featured_post`
)
VALUES
(
    'nepal',
    'pkr',
    'ratekhoire',
    'fulbari',
    '45',
    '1s',
    '0',
    '7',
    '10000',
    '9846586583',
    'bhabi',
    'Y'
)

I would actually recommend changing from int to String (ie varchar(numOfDigits) ) so you can allow prefix zeroes or pluses in the phone number. 我实际上建议将int更改为String (即varchar(numOfDigits) ),以便您可以在电话号码中允许前缀零或加号。 Then you can parse them with two helper methods. 然后,您可以使用两种辅助方法来解析它们。

int(16) has a maxvalue of 32767 since it's only 2 bytes = 16 bits (you can check that by converting the binary value 111111111111111 to decimal. int(16)的最大值为32767,因为它只有2个字节= 16位(您可以通过将二进制值111111111111111转换为十进制来进行检查。

ADDITION The number 2147483647 has a binary equivalent of ( 1100110011001100110011001100 which is just less than 4 bytes. (unsigned would be twice as big in decimal but not memory wise) 另外 ,数字2147483647的二进制等效项为( 1100110011001100110011001100 ,该字节数小于4个字节。

Reason: 原因:

2147483647 is the largest int value for MySQL. 2147483647是MySQL的最大int值。
The reason is because the maximum value for signed integer is 2147483647. Even if you have specify INT(16) that doesn't mean that you can store up length of 16 because the maximum allowable value is 2147483647. The meaning of 16 in INT declaration is the length of padded zero and is only applicable if ZEROFILL is enabled on the column. 原因是因为有符号整数的最大值为2147483647。即使您指定了INT(16),也并不意味着您可以存储16的长度,因为最大允许值为2147483647。INT声明中16的含义是填充的零的长度,并且仅在列上启用了ZEROFILL时才适用。 But still the length cannot reach up to 16 characters. 但是长度仍然不能达到16个字符。

If you have save the original data as 9846586583, it will be truncated into the maximum value of 2147483647. 如果您将原始数据另存为9846586583,它将被截断为最大值2147483647。


Solution: 解:

Just change the datatype from int to either bigint or varchar . 只需将数据类型从int更改为bigintvarchar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM