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
Post a Comment