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 に答える