IP地址存储在mysql数据库中 [英] IP address storing in mysql database

查看:144
本文介绍了IP地址存储在mysql数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是mysql的IP地址的正确的字段类型?

what is the right field type for IP address in mysql? and what is the right way of storing it?

推荐答案

This tutorial might help you.

保存IPv4地址最有效的方法是使用INT字段(不是您可能期望的VARCHAR)。您可以使用PHP的 ip2long 转换,然后使用MySQL的 INET_NTOA 函数或PHP的 long2ip 函数。

The most efficient way of saving IPv4 addresses is with an INT field (not VARCHAR as you might expect). You convert them using PHP's ip2long and back using either MySQL's INET_NTOA function or PHP's long2ip function.

如果你需要存储IPv6,你需要使用BINARY字段,而PHP inet_pton 功能。

If you need to store IPv6, you'll want to use a BINARY field instead and PHP's inet_pton function.

这篇关于IP地址存储在mysql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆