insert ip into mysql

浪尽此生 提交于 2019-12-25 02:02:16

问题


I came accross this statement for inserting an IP into a mysql table.

INSERT INTO `best` VALUES (132+256*(172+256*(109+256*(115))

I would like to know why an IP is being inserted this way, and how to actually work out what IP is being inserted


回答1:


Its prefer storing the IP address in decimal (integer) as it makes it easier to work with later.

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

see this links:

http://www.countryipblocks.net/networking/ip-address-conversion-to-decimal-and-binary-equivalents/

http://www.webproworld.com/web-programming-discussion-forum/85464-storing-ip-location-mysql-database.html




回答2:


that's way used to reduce the space used to store ip.

with this way you will store IPs in int type field, that is smaller in space than char type



来源:https://stackoverflow.com/questions/2175465/insert-ip-into-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!