Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


IP-Country DB Tables

Posted on 2006-07-13
Medium Priority
Last Modified: 2013-12-12
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 .

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"

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` (
`country_code2` INT( 2 ) NOT NULL ,
`country_code3` INT( 3 ) NOT NULL ,
`country_name` VARCHAR( 55 ) 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.

Question by:blaadom
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 40

Accepted Solution

Richard Quadling earned 375 total points
ID: 17106702

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

662 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question