So I know a lot of the time people look around for a database with country names and country codes and sometimes they can be hard to find and it can be a real bitch (Time consuming) to do one up yourself so here is a link to a sql dump I did which has 234 country names and there country codes that go with them.
http://www.amplegains.com/countries.sql
How Do I Use
Here are a few code examples of how you can use this database, lets say you know the country the user is from but you want to know the country code then you go like this.
Or what if you wanted to know the country name but you only have the country code, then you can go like this.
Or if you don't know the country name or country code but you are using PHP then we can use there IP address in order to get there country code without using the database by doing this.
This method is not 100% reliable though because its dependent on the outside website.
Finally this type of shit should be used in your site so that you can serve Canada only ads to canadians and US only ads to people in the USA and so on.
Enjoy.
http://www.amplegains.com/countries.sql
How Do I Use
Here are a few code examples of how you can use this database, lets say you know the country the user is from but you want to know the country code then you go like this.
Code:
db_connect();
$query = "SELECT code FROM countries WHERE name = '$country'";
$result = @mysql_query($query);
while($row = @mysql_fetch_array($result)) {
$country = strtolower($row['code']);
}
db_close();
Code:
db_connect();
$query = "SELECT name FROM countries WHERE code = '$code'";
$result = @mysql_query($query);
while($row = @mysql_fetch_array($result)) {
$code = strtolower($row['name']);
}
db_close();
Code:
$country = file_get_contents('http://api.hostip.info/country.php?ip='.$_SERVER['REMOTE_ADDR']);
Finally this type of shit should be used in your site so that you can serve Canada only ads to canadians and US only ads to people in the USA and so on.
Enjoy.