gpt4 book ai didi

php - 当我尝试插入 ip2long 整数时,错误的整数被插入到表中

转载 作者:行者123 更新时间:2023-11-29 06:31:05 25 4
gpt4 key购买 nike

我的代码:

$ip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'][0]); // Gives an IP address string. Example: "176.10.99.207"

$ipL = ip2long($ip); // An integer, which for this example would be 2953470927.

if( $stmt_insert_ip = $ip_link->prepare("INSERT INTO dataTable(ip,datetime) VALUES(?,?)") ){
$stmt_insert_ip->bind_param('is',$ipL,date("Y-m-d H:i:s"));
}

但是当我检查我的 MySQL 表时,ip 列下新插入的值是 2147483647,即“127.255.255.255”。

但是,当我运行 echo($ipL); 时,我得到 2953470927。

这里的 H-E-Double 曲棍球棒是怎么回事?

最佳答案

我假设您在数据库中使用了 INT 作为数据类型。简而言之,只需将 ip 列的数据类型更改为 BIGINT 即可解决问题。

INT range (-2147483648, 2147483647)
BIGINT range (-9223372036854775808, 9223372036854775807)

2953470927 超出了有符号 INT 的范围。

引用:MySQL: Integer types

关于php - 当我尝试插入 ip2long 整数时,错误的整数被插入到表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27882481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com