php - Which MySQL datatype to use for an IP address? -


possible duplicate:
how store ip in mysql

i want ip address $_server['remote_addr'] , other $_server variables, datatype right 1 this?

is varchar(n)?

since ipv4 addresses 4 byte long, use int (unsigned) has 4 bytes:

`ipv4` int unsigned 

and inet_aton , inet_ntoa convert them:

insert `table` (`ipv4`) values (inet_aton("127.0.0.1")); select inet_ntoa(`ipv4`) `table`; 

for ipv6 addresses use binary instead:

`ipv6` binary(16) 

and use php’s inet_pton , inet_ntop conversion:

'insert `table` (`ipv6`) values ("'.mysqli_real_escape_string(inet_pton('2001:4860:a005::68')).'")' 'select `ipv6` `table`' $ipv6 = inet_pton($row['ipv6']); 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -