PHP Classes

File: php_and_mysql.txt

Recommend this page to a friend!
  Classes of Bas Jobsen  >  Storeip  >  php_and_mysql.txt  >  Download  
File: php_and_mysql.txt
Role: Documentation
Content type: text/plain
Description: IMPORTANT
Class: Storeip
Store ip-addresses in a database
Author: By
Last change:
Date: 20 years ago
Size: 1,537 bytes


Class file image Download
After posting this class at

I got serveral emails about mysql default function
to do to same (in a better way (?)) and the same for

For MYSQL>=2.23:

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("");
->  3520061480
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.


Thanks to:
AzDG <>
Michael Brunson <>
FOR PHP>=4.0
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.

Thanks to:
Alexei Saveliev <>
For more information send a message to info at phpclasses dot org.