Some database structure ip addresses are stored in int type and converted using ip2long. However, this function seems to have a bug. What do you think? Some database structure ip addresses are stored in int type and converted using ip2long. However, this function seems to have a bug. What do you think?
Reply content:
Some database structure ip addresses are stored in int type and converted using ip2long. However, this function seems to have a bug. What do you think?
Mysql can refer to this answer.
Postgres directly belongs to the network address type. For more information, see here.
Use varchar or char
Reason:
1. Saving the conversion process
2. Both ipv4 and ipv6 can be stored.
It is not good to store both types.
Generally, a website simply uses varchar (15) to record user information.
Int is generally used for ip database, and it is easy to query the province and city of an ip address by segment record.
Use int to save space. Only four bytes are used. Use 7 to char ~ 15 bytes.
The most important thing is convenient query and comparison (numerical comparison), and setting an integer as an index is also more efficient than char.