#!/usr/bin/env php [-d ] [-b ] [-t ] [-u ] [-p ]\n"); } switch (strtolower($type)) { case "country-lite": $dbtype = DBIP::TYPE_COUNTRY_LITE; break; case "country-ipinfo": $dbtype = DBIP::TYPE_COUNTRY_IPINFO; break; case "city-lite": $dbtype = DBIP::TYPE_CITY_LITE; break; case "country": $dbtype = DBIP::TYPE_COUNTRY; break; case "location": $dbtype = DBIP::TYPE_LOCATION; break; case "isp": $dbtype = DBIP::TYPE_ISP; break; case "full": $dbtype = DBIP::TYPE_FULL; break; default: echo "invalid database type\n"; exit(1); } try { // Connect to the database $db = new PDO("mysql:{$host}=localhost;dbname={$dbname};charset=utf8mb4", $username, $password); // Alternatively connect to MySQL using the old interface // Comment the PDO statement above and uncomment the mysql_ calls // below if your PHP installation doesn't support PDO : // $db = mysql_connect("localhost", $username, $password); // mysql_select_db($dbname, $db); // Instanciate a new DBIP object with the database connection $dbip = new DBIP($db); //DBIPMySQLI // Alternatively instanciate a DBIP_MySQL object // Comment the new statement above and uncomment below if your PHP // installation doesn't support PDO : // $dbip = new DBIPMySQL($db); $nrecs = $dbip->importFromCsv($filename, $dbtype, $table, function($progress) { echo "\r{$progress} ..."; }); echo "\rfinished importing " . number_format($nrecs) . " records\n"; } catch (DBIPException $e) { echo "error: {$e->getMessage()}\n"; }