\MaxMind\DbReader

Instances of this class provide a reader for the MaxMind DB format. IP addresses can be looked up using the get method.

Summary

Methods
Properties
Constants
__construct()
get()
getWithPrefixLen()
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  $database) : mixed

Constructs a Reader for the MaxMind DB format. The file passed to it must be a valid MaxMind DB file such as a GeoIp2 database file.

Parameters

string $database

the MaxMind DB file to use

Throws

\InvalidArgumentException

for invalid database path or unknown arguments

\MaxMind\Db\Reader\InvalidDatabaseException

if the database is invalid or there is an error reading from it

Returns

mixed —

get()

get(string  $ipAddress) : mixed

Retrieves the record for the IP address.

Parameters

string $ipAddress

the IP address to look up

Throws

\BadMethodCallException

if this method is called on a closed database

\InvalidArgumentException

if something other than a single IP address is passed to the method

\MaxMind\Db\Reader\InvalidDatabaseException

if the database is invalid or there is an error reading from it

Returns

mixed —

the record for the IP address

getWithPrefixLen()

getWithPrefixLen(string  $ipAddress) : array

Retrieves the record for the IP address and its associated network prefix length.

Parameters

string $ipAddress

the IP address to look up

Throws

\BadMethodCallException

if this method is called on a closed database

\InvalidArgumentException

if something other than a single IP address is passed to the method

\MaxMind\Db\Reader\InvalidDatabaseException

if the database is invalid or there is an error reading from it

Returns

array —

an array where the first element is the record and the second the network prefix length for the record

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() : void

Closes the MaxMind DB and returns resources to the system.

Throws

\Exception

if an I/O error occurs