问题描述
我遇到了将IP插入mysql表的声明.
I came accross this statement for inserting an IP into a mysql table.
INSERT INTO `best` VALUES (132+256*(172+256*(109+256*(115))
我想知道为什么以这种方式插入IP,以及如何实际算出要插入的IP
I would like to know why an IP is being inserted this way, and how to actually work out what IP is being inserted
推荐答案
它更喜欢以十进制(整数)存储IP地址,因为这样以后可以更轻松地使用它.
Its prefer storing the IP address in decimal (integer) as it makes it easier to work with later.
但是您可以使用MySQL命令轻松地转换数据.例如,如果您检索了IP,则可以使用 inet_aton('$ip')
命令将插入的IP地址($ ip)转换为十进制,然后将数据添加到数据库中.您可以使用 inet_ntoa
But you can use MySQL commands to easily convert the data. For instance if you retrieved the IP you can use the inet_aton('$ip')
command to convert the insert the IP Address ($ip) into decimal and then add the data into the database. You can convert the Decimal Address back to octets by using inet_ntoa
查看此链接:
http://www. countryipblocks.net/networking/ip-address-conversion-to-decimal-binary-equivalents/
这篇关于将ip插入mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!