A note about converting IP addresses for storage in database.  For MySQL, this is unnecessary as it has built in support via the INET functions.  Also, there is no need to use BIGINT.  UNSIGNED INT is, at 4 bytes, the perfect size for holding an IP (column must be defined as UNSIGNED).  This can basically halve the storage size, as BIGINT is an 8 byte data type.
INET_ATON() converts a dotted IP string to INT:
INSERT table(ip) VALUES(INET_ATON('127.0.0.1'));
INET_NTOA() converts an INT to dotted IP string:
SELECT INET_NTOA(ip) FROM table
returns '127.0.0.1'
Details:
http://dev.mysql.com/doc/refman/5.1/en/miscellaneous-functions.html

posted on 2009-12-16 20:55  菜根talk  阅读(589)  评论(0编辑  收藏  举报