Web Hosting Info

Search:

featured partner

The IP to Country Database

  Forum Topics : Development / Inserting ip-to-country csv into a mysql db
Submitted by tobo- on Thu, 07/17/2003 - 07:28.
I've written a tiny little tool that reads the ip2country csv file then inserts it into a database.

It is configurable in the .php file and probaly not perfect, but I will try to correct the bugs.

You can reach it at iptocountry.nyoc.hu, and there's also a dump of my mysql db, which uses the May-version of the ip2c.
Comment viewing options:
Select your preferred way to display the comments and click 'Save settings' to submit your changes.
Cool! :)
Posted by sandeep on Tue, 07/22/2003 - 15:04.
You could alternatively use MySQL's LOAD DATA
 
Ipmatch site changes
Posted by mediainterface on Fri, 03/25/2005 - 13:08.
Hello all!

as an ip-to-country db test site, I had created my http://www.media-interface.biz/ipmatch.php now until a new hosting is set up the address http://213.244.187.83/ipmatch.php is better used.

In my pages, the .csv load procedure (on the server side) is described.
Regards
MySQL update
Posted by Kurt on Sun, 08/10/2003 - 05:31.
Great service! Thank you very much.

I run a remotley hosted server and updating the files on the MySQL database mostly caused timeouts, etc.
As i only need the FROM and TO range and the top level domain output (US, AU, etc.) i wrote the small utility below.
The 'ip-to-country.csv' raw file can be uploaded to the server, the file containing the utility can be called and the MySQL db is updated in a flash.


$db = mysql_connect("localhost","username", "password");
mysql_select_db("database_name",$db);

$query="DELETE FROM ip_num";
$result = mysql_query($query,$db);

$fp=fopen('ip-to-country.csv', 'r');

while(!feof($fp)) {

$row=fgets($fp, 4096);
$data=explode("\"", $row);

$query="insert into ip_num VALUES ('$data[1]','$data[3]','$data[5]')";
$result = mysql_query($query,$db);

$num++;
}
mysql_close($db);
fclose($fp);
 
PHP fgetcsv
Posted by sandeep on Tue, 08/12/2003 - 14:58.
You could alternatively use the PHP fgetcsv function.
What gives....??
Posted by scamout on Fri, 08/15/2003 - 14:56.
I had this thing working!!!

I downloaded the latest .csv but it won't load into the mySQL properly. Depending on how I do it, I either get only half the number of rows or I get them all but only the first row has the ip_from and the rest have 0000000

It's got to be me. What am I doing wrong?!?!


Tom Mahoney, Director
merchant911.org
Problem with Ivory Coast
Posted by MrO on Wed, 08/20/2003 - 03:29.
the SQL-statement should be changed to

$sql="insert into ".$mysql["table"]["name"]." ".
"(`".$mysql["table"]["ip_from"]."`, "
."`".$mysql["table"]["ip_to"]."`, "
."`".$mysql["table"]["code"]."`, "
."`".$mysql["table"]["country"]."`) values ".
"('".$ip_start."', '".$ip_end."', '".$code."', '".addslashes($country)."')";

You have to add 'addslashes' because the country name is Cote D'Ivoir.

This should solve the problem!
 
Wrong entry in db
Posted by chaos21in on Sat, 04/30/2005 - 10:48.
read next posting..
 
Wrong entry in db
Posted by chaos21in on Sat, 04/30/2005 - 10:54.
I tried to put all the csv data from file to mysql database but there is following problem:

The entries around line no. 11361 in csv file are:

2083734592,2113929215,AU,AUS,AUSTRALIA
2113929216,2130706431,JP,JPN,JAPAN
2147483648,2147942399,US,USA,UNITED STATES
2147942400,2148007935,DE,DEU,GERMANY
2148007936,2148532223,US,USA,UNITED STATES

But instead in the mysql databse theses are ;

| 2083734592 | 2113929215 | AUS | AUSTRALIA |
| 2113929216 | 2130706431 | JPN | JAPAN |
| 2147483647 | 2147483647 | USA | UNITED STATES |
| 2147483647 | 2147483647 | DEU | GERMANY |
| 2147483647 | 2147483647 | USA | UNITED STATES |

and so on and so fourth...all the remaining entries for ipFrom and ipTo are same and equal to 2147483647 .

any idea why it happend and how to put database in mysql correctly.
 
I got the problem and solutio
Posted by chaos21in on Tue, 05/03/2005 - 11:42.
I got the problem and solutions...the problem is the type of ipFrom and ipTo i choose int(15) and apparently the max int possible is 2147483647, so now when i used bigint(20) instead , it worked..