Link to home
Start Free TrialLog in
Avatar of blaadom
blaadom

asked on

IP-Country DB Tables

hi guys,

I'm setting up a system which detects what country a user is from by running a query on the IP-to-Country database which i downloaded as a CSV file from www.ip-to-country.webhosting.info .

I found a script which queries the database using the following syntax:
$country_query  = "SELECT country_code2,country_name, FROM iptoc ".
         "WHERE IP_FROM<=inet_aton('$REMOTE_ADDR') ".
          "AND IP_TO>=inet_aton('$REMOTE_ADDR') ";

The CSV file has the following layout:

"33996344","33996351","GB","GBR","UNITED KINGDOM"
"50331648","69956103","US","USA","UNITED STATES"
"69956104","69956111","BM","BMU","BERMUDA"

The documentation for the CSV file states that " The CSV file contains four fields:

    * Begining of IP address range
    * Ending of IP address range
    * Two-character country code based on ISO 3166
    * Three-character country code based on ISO 3166
    * Country name based on ISO 3166 "

So how should i setup my database tables/fields?  Obviously i have to have an ID field which auto increments, and i will be adding a field for paths for flags, but what other fields should i have? This is the SQL i'm working with now

CREATE TABLE `tables` (
`id` INT( 5 ) NOT NULL AUTO_INCREMENT ,
`country_code2` INT( 2 ) NOT NULL ,
`country_code3` INT( 3 ) NOT NULL ,
`country_name` VARCHAR( 55 ) NOT NULL ,
`IP_FROM` INT( 12 ) NOT NULL ,
`IP_TO` VARCHAR( 12 ) NOT NULL ,
`flag` INT( 12 ) NOT NULL ,
PRIMARY KEY ( `id` )
) CHARACTER SET = latin1;

Also how do i import all the values from the CSV file? I've never used one before.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial