简体   繁体   English

将数据库中的IP地址存储为整数

[英]Storing IP address in database as integer

i'm storing ip adress in database as integer, with ip2long() , column type is unsigned int, but for some ip in database it saves as 0, i tested and some ip for ip2long function returns negative integer and when i insert it in database it saves as 0. i googled and everyone says that column must be unsigned int. 我将ip地址存储在数据库中作为整数,使用ip2long() ,列类型是unsigned int,但是对于数据库中的某些ip,它保存为0,我测试了一些ip for ip2long函数返回负整数,当我插入它时数据库它保存为0.我googled,每个人都说该列必须是unsigned int。

for example: ip2long("212.36.25.15"); 例如: ip2long("212.36.25.15"); will return -735831793 and in database it will be saved as 0 将返回-735831793并在数据库中将其保存为0

Insert the ip address using INET_ATON. 使用INET_ATON插入IP地址。
eg: INET_ATON('127.0.0.1'); 例如:INET_ATON('127.0.0.1');
get back the ip address using INET_NTOA 使用INET_NTOA获取IP地址
eg: SELECT INET_NTOA('2130706433'); 例如:SELECT INET_NTOA('2130706433');

您可以使用MySQL函数INET_ATON。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM