आपको लगता है कि पीएचपी अंदर से निपटने के लिए नहीं होना चाहिए करने के लिए इसे डाली, कि क्या MySQL देशी funcions के लिए कर रहे हैं। इस उदाहरण देखें:
create table iptable (
ip int(32) unsigned not null,
comment varchar(32) not null
);
insert into iptable (ip, comment) values (inet_aton('10.0.0.3'), 'This is 10.0.0.3');
select * from iptable;
+-----------+------------------+
| ip | comment |
+-----------+------------------+
| 167772163 | This is 10.0.0.3 |
+-----------+------------------+
select inet_ntoa(ip) as ip, comment from iptable;
+----------+------------------+
| ip | comment |
+----------+------------------+
| 10.0.0.3 | This is 10.0.0.3 |
+----------+------------------+
आप दोनों IPv4 और एक ही क्षेत्र में आईपीवी 6 से निपटने के लिए चाहते हैं, और आप Mysql 5.6 या अधिक प्रयोग कर रहे हैं, तो आप varbinary (16) और inet6_aton कार्य करता है और inet6_ntoa उपयोग कर सकते हैं। यही कारण है कि आप MySQL कार्यों का उपयोग और नहीं पीएचपी अंदर बाइनरी डेटा के साथ सौदा करना चाहिए का एक बेहतर उदाहरण है:
create table iptable2 (
ip varbinary(16) not null,
comment varchar(32) not null
);
insert into iptable2 (ip, comment) values
(inet6_aton('192.168.1.254'), 'This is router 192.168.1.254'),
(inet6_aton('::1'), 'This is ipv6 localhost ::1'),
(inet6_aton('FE80:0000:0000:0000:0202:B3FF:FE1E:8329'), 'This is some large ipv6 example')
;
select * from iptable2;
+------------------+---------------------------------+
| ip | comment |
+------------------+---------------------------------+
| +¿?¦ | This is router 192.168.1.254 |
| ? | This is ipv6 localhost ::1 |
| ¦Ç ??¦ ¦?â) | This is some large ipv6 example |
+------------------+---------------------------------+
select inet6_ntoa(ip) as ip, comment from iptable2;
+--------------------------+---------------------------------+
| ip | comment |
+--------------------------+---------------------------------+
| 192.168.1.254 | This is router 192.168.1.254 |
| ::1 | This is ipv6 localhost ::1 |
| fe80::202:b3ff:fe1e:8329 | This is some large ipv6 example |
+--------------------------+---------------------------------+
आप देख सकते हैं कि ऐसा करने से, आप वास्तव में विभिन्न स्वरूपों में IPv6 पतों का मूल्यांकन करने से बच सकते हैं, क्योंकि MySQL उन्हें बाइनरी में बदल देता है और वापस अपनी सबसे सरल अभिव्यक्ति में बदल जाता है।
मुझे पता है कि इस प्रश्न में 2 से अधिक वर्षों पहले से ही हैं, लेकिन मैं यह जानकारी उन लोगों के लिए उपयोगी होना चाहता हूं जो आने वाले हैं।
HTH
फ्रांसिस्को Zarabozo
स्रोत
2013-03-12 20:18:17
जोड़ने के लिए, मैं, स्थानीय होस्ट पर काम कर रहा हूँ तो शायद इसलिए है भूल ip2long() कुछ भी वापस नहीं कर रहा है? – blerh
लोकहोस्ट का आईपीवी 4 अभी भी 127.0.0.1 है, इसे तब तक काम करना चाहिए जब तक आप आईपीवी 6 का उपयोग नहीं कर रहे हों - मेरा जवाब देखें। –