dongxie548548 2011-10-10 12:31
浏览 213
已采纳

在mySQL中使用填充数据自动创建表或行

I'm looking to create a basic IP management solution using a web front end with PHP and MySQL. I am not too familiar with PHP or MySQL but I would like to know if it would be possible to do the following:

When a user inserts a new subnet range into the database (e.g 192.168.1.0/24) using a HTML form, would it be possible for that to trigger another create table (e.g. ip_addresses) that would auto-populate the table with the subnet range (e.g. 192.168.1.1, 1.2, 1.3 and so on).

Apologies if I'm being too vague - thanks

  • 写回答

2条回答 默认 最新

  • dpdt79577 2011-10-10 12:36
    关注

    Though it would be possible to do what you are asking, I would advise against it. In MySQL, it is common to store IP addresses as long integers, rather than as their string representation as a dotted quad. MySQL provides two functions, INET_ATON() and its counterpart INET_NTOA() to convert IP addresses into long integers.

    The structure I would recommend would be to store the starting and ending integer representation of the subnets. That way, it becomes possible, if necessary to query for addresses residing between the endpoints. Also it allows you to store incomplete subnets.

    From MySQL docs:

    mysql> SELECT INET_ATON('10.0.5.9');
            -> 167773449
    mysql> SELECT INET_NTOA(167773449);
            -> '10.0.5.9'
    

    You can query with statements like:

    SELECT * ipRanges WHERE INET_ATON('192.168.1.99') BETWEEN startIpNum AND endIpNum;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错