mirror of
https://github.com/php/presentations.git
synced 2026-03-24 07:32:11 +01:00
23 lines
422 B
PHP
23 lines
422 B
PHP
<?php
|
|
$db = sqlite_open("./ip.db");
|
|
|
|
$fp = fopen("./ip-to-country.csv", "r");
|
|
// read ip information 1 entry at a time
|
|
while (($row = fgetcsv($fp, 4096))) {
|
|
/* sample row
|
|
Array
|
|
(
|
|
[0] => 33996344
|
|
[1] => 33996351
|
|
[2] => GB
|
|
[3] => GBR
|
|
[4] => UNITED KINGDOM
|
|
)
|
|
*/
|
|
sqlite_query("INSERT INTO country_data
|
|
(cc_code_2, cc_code_3, country_name)
|
|
VALUES('{$row[2]}', '{$row[3]}', '{$row[4]}')",
|
|
$db);
|
|
}
|
|
fclose($fp);
|
|
?>
|