After posting this class at phpclasses.org
I got serveral emails about mysql default function
to do to same (in a better way (?)) and the same for
Use field properties for IPs
ip int unsigned NOT NULL default '0'
Use MySQL functions- from int to ip, and from ip to int
INET_NTOA(expr) Given a numeric network address (4 or 8 byte), returns the dotted-quad representation of the address as a string:
mysql> SELECT INET_NTOA(3520061480);
INET_ATON(expr) Given the dotted-quad representation of a network address as a string, returns an integer that represents the numeric
value of the address. Addresses may be 4 or 8 byte addresses:
mysql> SELECT INET_ATON("184.108.40.206");
The generated number is always in network byte order; for example the above number is calculated as 209*256^3 + 207*256^2 + 224*256 +40.
Michael Brunson <firstname.lastname@example.org>
You shouldn't even use this class!!
Use ip2long() and long2ip() insteads
Note: Because PHP's integer type is signed, and many IP addresses will result in negative integers, you need to use the "%u" formatter of sprintf() or printf() to get the string representation of the unsigned IP address.
Alexei Saveliev <email@example.com>