开发者

insert ip into mysql

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

INSERT INTO `best` VALUES (132+256*(172+256*(1开发者_JAVA百科09+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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜