<?php namespace GeoIP; error_reporting(-1); chdir(dirname(__FILE__)); require 'vendor/autoload.php'; try { $url = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country-CSV.zip'; $dbFile = 'db/geo.sdb'; @unlink($dbFile); $countryBlocks = ''; $countryLocations = ''; $files = Importer::getFiles($url, ['GeoLite2-Country-Blocks-IPv4.csv', 'GeoLite2-Country-Locations-en.csv']); $dbh = new \PDO('sqlite:' . $dbFile); $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $sql = file_get_contents('db/schema.sql'); $dbh->exec($sql); Importer::csvRead($files['GeoLite2-Country-Blocks-IPv4.csv'], function ($values) use($dbh) { $cidr = explode('/', $values['network']); $longStart = ip2long($cidr[0]) & -1 << 32 - $cidr[1]; $longEnd = ip2long($cidr[0]) + pow(2, 32 - $cidr[1]) - 1; $sth = $dbh->prepare(' INSERT INTO country_blocks ( network, long_start, long_end, geoname_id, registered_country_geoname_id, represented_country_geoname_id, is_anonymous_proxy,