<?php
$appName = 'mondialisa';
session_name($appName);
session_start();

require_once 'config.inc.php';

header('Content-Type: application/json; charset=utf-8');

$q = strtolower($_GET['q']) ?? '';

$stmt = $dbh->prepare("
    SELECT city as name, country 
    FROM mondialisa_cities 
    WHERE lower(city) LIKE ? and alpha2_country = ? 
    LIMIT 10
");

$stmt->execute(["%$q%",strtoupper($_SESSION['COUNTRY']['alpha2'])]);

echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
