0

我正在尝试将 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 做错了什么?

4

1 回答 1

1

您的问题不在于 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()
));
于 2013-09-30T06:23:15.853 回答