Columns for IP

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Columns for IP

Post by Ambush Commander »

Right now, I'm storing the IP string that PHP gives you in one column `ip`. But after reading about normalization, I'm having doubts. Is there a better way to do this? And what about IPv6?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Some databases provide an INET or CIDR, etc datatype that is designed for dealing with IP address and/or netmasks, etc. However often they are rather broken and just using the string is acceptable.

As the majority of the uses of the IP are atomic (you aren't splitting it into its octets for most things) it doesn't require normalization.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

And suppose you wanted to 23.45.*.*, how would you go about doing that?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

That's what the special types with netmasks/etc are for.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

I generally use strings, as that enables easy select/like searches.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Yes, I suppose you could use RegExps.
Post Reply