<?php
$servername = "109.106.254.1";
$username = "u353443769_beis";
$password = 'Te$t@dm1n';
$dbname = "u353443769_beis";

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

// Pārbaudīt savienojumu
if ($conn->connect_error) {
    die("Savienojums neizdevās: " . $conn->connect_error);
}

// Izgūt maksimālo ieraksta ID no datubāzes
$sql = "SELECT MAX(id) AS maxId FROM pav_gra_postsi";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    $row = $result->fetch_assoc();
    // Nosūtīt maksimālo ieraksta ID kā JSON atbildi
    header('Content-Type: application/json');
    echo json_encode(['maxId' => $row['maxId']]);
} else {
    echo json_encode(['error' => 'Nav atrasti ieraksti']);
}

$conn->close();
?>