In what ways can SQLite be a suitable alternative to traditional databases for managing data in PHP applications, especially when dealing with city names?

SQLite can be a suitable alternative to traditional databases for managing data in PHP applications, especially when dealing with city names, due to its lightweight nature and ease of use. With SQLite, you can store city names efficiently without the need for a separate database server, making it a convenient choice for smaller projects or applications where scalability is not a major concern.

// Connect to SQLite database
$db = new SQLite3('cities.db');

// Create a table to store city names
$db->exec('CREATE TABLE IF NOT EXISTS cities (id INTEGER PRIMARY KEY, name TEXT)');

// Insert a city name into the table
$cityName = 'New York';
$db->exec("INSERT INTO cities (name) VALUES ('$cityName')");

// Retrieve city names from the table
$results = $db->query('SELECT name FROM cities');
while ($row = $results->fetchArray()) {
    echo $row['name'] . "\n";
}

// Close the database connection
$db->close();