\GeoIp2\DatabaseReader

Instances of this class provide a reader for the GeoIP2 database format.

IP addresses can be looked up using the database specific methods.

Usage

The basic API for this class is the same for every database. First, you create a reader object, specifying a file name. You then call the method corresponding to the specific database, passing it the IP address you want to look up.

If the request succeeds, the method call will return a model class for the method you called. This model in turn contains multiple record classes, each of which represents part of the data returned by the database. If the database does not contain the requested information, the attributes on the record class will have a null value.

If the address is not in the database, an \GeoIp2\Exception\AddressNotFoundException exception will be thrown. If an invalid IP address is passed to one of the methods, a SPL \InvalidArgumentException will be thrown. If the database is corrupt or invalid, a \MaxMind\Db\Reader\InvalidDatabaseException will be thrown.

Summary

Methods
Properties
Constants
__construct()
city()
country()
anonymousIp()
asn()
connectionType()
domain()
enterprise()
isp()
metadata()
close()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__construct()

__construct(string  $filename, array  $locales = array('en')) 

Constructor.

Parameters

string $filename

the path to the GeoIP2 database file

array $locales

list of locale codes to use in name property from most preferred to least preferred

Throws

\MaxMind\Db\Reader\InvalidDatabaseException

if the database is corrupt or invalid

city()

city(string  $ipAddress) : \GeoIp2\Model\City

This method returns a GeoIP2 City model.

Parameters

string $ipAddress

an IPv4 or IPv6 address as a string

Throws

\GeoIp2\Exception\AddressNotFoundException

if the address is not in the database

\MaxMind\Db\Reader\InvalidDatabaseException

if the database is corrupt or invalid

Returns

\GeoIp2\Model\City

country()

country(string  $ipAddress) : \GeoIp2\Model\Country

This method returns a GeoIP2 Country model.

Parameters

string $ipAddress

an IPv4 or IPv6 address as a string

Throws

\GeoIp2\Exception\AddressNotFoundException

if the address is not in the database

\MaxMind\Db\Reader\InvalidDatabaseException

if the database is corrupt or invalid

Returns

\GeoIp2\Model\Country

anonymousIp()

anonymousIp(string  $ipAddress) : \GeoIp2\Model\AnonymousIp

This method returns a GeoIP2 Anonymous IP model.

Parameters

string $ipAddress

an IPv4 or IPv6 address as a string

Throws

\GeoIp2\Exception\AddressNotFoundException

if the address is not in the database

\MaxMind\Db\Reader\InvalidDatabaseException

if the database is corrupt or invalid

Returns

\GeoIp2\Model\AnonymousIp

asn()

asn(string  $ipAddress) : \GeoIp2\Model\Asn

This method returns a GeoLite2 ASN model.

Parameters

string $ipAddress

an IPv4 or IPv6 address as a string

Throws

\GeoIp2\Exception\AddressNotFoundException

if the address is not in the database

\MaxMind\Db\Reader\InvalidDatabaseException

if the database is corrupt or invalid

Returns

\GeoIp2\Model\Asn

connectionType()

connectionType(string  $ipAddress) : \GeoIp2\Model\ConnectionType

This method returns a GeoIP2 Connection Type model.

Parameters

string $ipAddress

an IPv4 or IPv6 address as a string

Throws

\GeoIp2\Exception\AddressNotFoundException

if the address is not in the database

\MaxMind\Db\Reader\InvalidDatabaseException

if the database is corrupt or invalid

Returns

\GeoIp2\Model\ConnectionType

domain()

domain(string  $ipAddress) : \GeoIp2\Model\Domain

This method returns a GeoIP2 Domain model.

Parameters

string $ipAddress

an IPv4 or IPv6 address as a string

Throws

\GeoIp2\Exception\AddressNotFoundException

if the address is not in the database

\MaxMind\Db\Reader\InvalidDatabaseException

if the database is corrupt or invalid

Returns

\GeoIp2\Model\Domain

enterprise()

enterprise(string  $ipAddress) : \GeoIp2\Model\Enterprise

This method returns a GeoIP2 Enterprise model.

Parameters

string $ipAddress

an IPv4 or IPv6 address as a string

Throws

\GeoIp2\Exception\AddressNotFoundException

if the address is not in the database

\MaxMind\Db\Reader\InvalidDatabaseException

if the database is corrupt or invalid

Returns

\GeoIp2\Model\Enterprise

isp()

isp(string  $ipAddress) : \GeoIp2\Model\Isp

This method returns a GeoIP2 ISP model.

Parameters

string $ipAddress

an IPv4 or IPv6 address as a string

Throws

\GeoIp2\Exception\AddressNotFoundException

if the address is not in the database

\MaxMind\Db\Reader\InvalidDatabaseException

if the database is corrupt or invalid

Returns

\GeoIp2\Model\Isp

metadata()

metadata() : \MaxMind\Db\Reader\Metadata

Throws

\InvalidArgumentException

if arguments are passed to the method

\BadMethodCallException

if the database has been closed

Returns

\MaxMind\Db\Reader\Metadata

object for the database

close()

close() 

Closes the GeoIP2 database and returns the resources to the system.