Skip to main content

IP2Location Extension

Commands

dbr.ip2location - Retrieves location data for a given IP address
dbr.ip2location.language - Sets the language for names returned by MaxMind (defaults to 'en'). Refer to MaxMind's documentation for supported language codes

Syntax

select 'dbr.ip2location', 'save_procedure_name'[, 'maxmind' | 'ip2location' | 'ipinfo' ]
select 'dbr.ip2location.language', language_code

Configuration

To configure the extension, override the 'ip2location' entry in $mydbr_defaults within user/extension_init.php. For example, add the following configuration with your credentials:

$mydbr_defaults['ip2location'] = [
'default_service_provider' => 'maxmind',
'maxmind' => [
'account_id' => 12345,
'license_key' => 'abcdefg'
],
'ip2location' => [
'api_key' => '12345',
'package' => 'WS6'
],
'ipinfo' => [
'token' => '123456'
]
];

Usage

The Save Procedure

The save procedure is responsible for persisting the retrieved geolocation data. The procedure should follow this format:

create procedure sp_geo_save_ip ( 
in_ip_address varchar(39),
in_country varchar(255),
in_city varchar(255),
in_latitude decimal(11,7),
in_longitude decimal(11,7),
in_isp varchar(255)
)
begin

insert ignore into my_ip2_location (ip_address, country, city, latitude, longitude, isp)
values (in_ip_address, in_country, in_city, in_latitude, in_longitude, in_isp);

end

Retrieving Geolocation Data

To retrieve and save location data for IP addresses:

select 'dbr.ip2location', 'sp_geo_save_ip';

select ip_address
from mydata;

Specifying the Service Provider

You can explicitly choose a service provider ('maxmind', 'ip2location', or 'ipinfo'):

select 'dbr.ip2location', 'sp_geo_save_ip', 'maxmind';

select ip_address
from mydata;

Below are examples for other supported providers:

-- Using IP2Location
select 'dbr.ip2location', 'sp_geo_save_ip', 'ip2location';

select ip_address
from mydata;

-- Using ipinfo
select 'dbr.ip2location', 'sp_geo_save_ip', 'ipinfo';

select ip_address
from mydata;