<?php
session_start();
$id = $_SESSION['id'];
$db = new SQLite3("./api/db/studiolivecode_clientes.db");

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['key'])) {
    $key = $_POST['key'];
    
    $stmt = $db->prepare("SELECT * FROM ibo WHERE key = :key AND id_user IS NULL");
    $stmt->bindValue(':key', $key, SQLITE3_TEXT);
    $result = $stmt->execute();

    $data = [];
    while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
        $data[] = $row;
    }

    echo json_encode($data);
}
?>
