What are some common sources for obtaining a list of countries and their cities in SQL format for PHP applications?

To obtain a list of countries and their cities in SQL format for PHP applications, one common source is to use a pre-existing database that contains this information. Another option is to find online resources or APIs that provide country and city data in SQL format. You can also manually create a SQL database with tables for countries and cities and populate it with the necessary data.

// Example code snippet to create a SQL database table for countries and cities

// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

$conn = new mysqli($servername, $username, $password, $dbname);

// Create table for countries
$sql_countries = "CREATE TABLE countries (
    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50) NOT NULL
)";

$conn->query($sql_countries);

// Create table for cities
$sql_cities = "CREATE TABLE cities (
    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    country_id INT(6) UNSIGNED,
    FOREIGN KEY (country_id) REFERENCES countries(id)
)";

$conn->query($sql_cities);

// Populate tables with country and city data
// Insert statements go here

// Close the connection
$conn->close();