<?php
declare(strict_types=1);
// Read-only, zero-row syntax proof against the approved nonproduction instance.
$env = [];
foreach (explode("\0", (string)file_get_contents('/proc/53772/environ')) as $entry) {
    $pair = explode('=', $entry, 2);
    if (count($pair) === 2) $env[$pair[0]] = $pair[1];
}
if (($env['POC_AI_HOST'] ?? '') !== '127.0.0.1'
    || ($env['POC_AI_PORT'] ?? '') !== '5238'
    || ($env['POC_AI_SCHEMA'] ?? '') !== 'AIZHCT_APP') exit(78);
$pdo = new PDO('dm:host=127.0.0.1;port=5238;schema=AIZHCT_APP',
    $env['POC_AI_USER'], $env['POC_AI_PASSWORD'], [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
$results = [];
foreach (['unquoted' => 'SELECT domain FROM YOSHOP_UPLOAD_FILE WHERE 1=0',
    'quoted' => 'SELECT "DOMAIN" FROM YOSHOP_UPLOAD_FILE WHERE 1=0'] as $key => $sql) {
    try {
        $rows = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
        $results[$key] = ['success' => true, 'rows' => count($rows)];
    } catch (PDOException $error) {
        $results[$key] = ['success' => false, 'sqlstate' => $error->errorInfo[0] ?? null,
            'native_code' => $error->errorInfo[1] ?? null];
    }
}
echo json_encode(['scope' => 'zero-row SELECT only; no ORM or HTTP acceptance', 'results' => $results]), "\n";
exit($results['unquoted']['success'] || !$results['quoted']['success'] ? 1 : 0);
