die;
}
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$items = $stmt->fetchAll();
$stmt->closeCursor();
foreach ($items as &$item) {
    //var_dump($item);
    if ($item['l_location_city'] == 'Москва') {
        updateAds($item['l_location_city'], 1055864, 554889, $db);
        continue;
    }
    if ($item['l_location_city'] == 'Санкт-Петербург') {
        updateAds($item['l_location_city'], 1059979, 508324, $db);
        continue;
    }
    $isSet = checkIsSet($item['l_location_city'], $db);
    if ($isSet === true) {
        continue;
    }
    $sql = 'SELECT id, code, name FROM ru_geo.kladr WHERE name= :name AND socr="г" AND SUBSTRING(code,12,2)="00"';
    $stmt = $db->prepare($sql);
    $stmt->bindParam(':name', $item['l_location_city'], PDO::PARAM_STR);
    $res = $stmt->execute();
    if ($res === false) {
        print_r($stmt->errorInfo());
        die;
    }
    $stmt->setFetchMode(PDO::FETCH_ASSOC);
    $kladrItems = $stmt->fetchAll();
    $stmt->closeCursor();
    if (count($kladrItems) > 1 || empty($kladrItems)) {
$stmt->closeCursor();
foreach ($items as &$item) {
    //var_dump($item);
    $region_id = $item['region_id'];
    $subregion_id = null;
    if ($item['region_id'] == 554889 && $item['l_geo_city'] == 'Москва') {
        $city_id = 1055864;
        updateAds($item['l_geo_city'], $city_id, $subregion_id, $region_id, $item['old_region_id'], $db);
        continue;
    }
    if ($item['region_id'] == 508324 && $item['l_geo_city'] == 'Санкт-Петербург') {
        $city_id = 1059979;
        updateAds($item['l_geo_city'], $city_id, $subregion_id, $region_id, $item['old_region_id'], $db);
        continue;
    }
    $isSet = checkIsSet($item['l_geo_city'], $item['old_region_id'], $db);
    if ($isSet === true) {
        continue;
    }
    if (!empty($item['region_code'])) {
        $parentCodeSql = ' AND SUBSTRING(code,1,2)= :parent_code ';
    } else {
        $parentCodeSql = '';
    }
    $where = getKladrWhere($item['l_geo_city']);
    $sql = 'SELECT id, code, name FROM ru_geo.kladr WHERE name= :name AND socrname= :socrname AND SUBSTRING(code,12,2)="00" ' . $parentCodeSql;
    $stmt = $db->prepare($sql);
    $stmt->bindParam(':name', $where['name'], PDO::PARAM_STR);
    $stmt->bindParam(':socrname', $where['socrname'], PDO::PARAM_STR);
    if (!empty($item['region_code'])) {
        $parentCode = substr($item['region_code'], 0, 2);