php - ip地址存储建议用int还是varchar(15),效率有差别吗
巴扎黑
巴扎黑 2017-04-10 14:52:21
0
5
696

看到有的数据库结构ip用int存储,然后通过ip2long转化,不过这个函数好像有bug,大家怎么看?

巴扎黑
巴扎黑

répondre à tous(5)
刘奇

Mysql可以参考这个答案。

Postgres直接由网络地址类型,参考这里

巴扎黑

用varchar或者char
理由:
1.省去转化的过程
2.ipv4或ipv6的都可以存

Ty80

两种都存不就好

黄舟

一般网站只是记录用户的一些信息用varchar(15)就行了
int一般是做ip库用的,容易分段记录查询一个ip的所属省市等

刘奇

用int存省空间,只用4个字节,char的话要用7~15个字节。
最重要的是方便查询比较(数值比较),而且设置整形为索引也比char效率高。

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!