【发布时间】:2026-01-03 15:20:06
【问题描述】:
我正在尝试将 ip 地址存储到我的数据库中,我正在使用INET_ATON,如下所示,
$sql = "
INSERT INTO pin (
page_id,
user_id,
pc_name,
ip,
geolocation,
created_on
)VALUES(
?,
?,
?,
?,
?,
NOW()
)";
$result = $this->connection->executeSQL($sql,array(
$this->page_id,
$this->user_id,
$this->getComputerName(),
'INET_ATON("123.136.106.104")',
$this->getGeoLocation()
));
但我无法将其转换或保存到数据库中的ip 字段中。我得到0 而不是数字。
我该怎么办?我在 SQL 上做错了什么?
【问题讨论】:
-
我怀疑你要插入的是
VALUES(?,?,?,?,INET_ATON(?),NOW()),只是将IP作为字符串参数传递。 -
使用 ip2long() 和 long2ip()。关注此帖子以供参考 [*.com/questions/2754340/… [1]:*.com/questions/2754340/…
标签: php mysql ip php-5.4 inet-aton