I have a CSV file downloaded from Maxmind which contains IPv6 data. I need to upload it to MySql table and then use this table to detect a country by IPv6.
So the first question is what the MySql type should be LONGSTART
and LONGEND
fields in my MySQL table as max INTEGER length can be of 20 while I have 42540488558116655331872044393019998208
number?
And the other question is how to build a MySql query in order to find an IP address between LONGSTART
and LONGEND
? I use a function( ipv6_numeric($ip)
) which converts '2001::11ff:ffff:f'
IPv6 address into a long number like 2540488558116655331872044393019998208
.
Thanks for advance!
You can use the following simple SQL query.
SELECT * FROM `geoip2`
WHERE [SEARCH IP NO] <= LONGEND LIMIT 1