[英]PHP MySQL: INET_ATON does not save data?
我正在尝试将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做错了什么?
您的问题不在INET_ATON函数中,而是在PDO(我假设它是PDO)如何解释绑定参数中。 您可以这样操作:
$sql = "
INSERT INTO pin (
page_id,
user_id,
pc_name,
ip,
geolocation,
created_on
)VALUES(
?,
?,
INET_ATON(?),
?,
?,
NOW()
)";
并通过您的IP:
$result = $this->connection->executeSQL($sql,array(
$this->page_id,
$this->user_id,
$this->getComputerName(),
"123.136.106.104",
$this->getGeoLocation()
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.