<?php
require_once 'main_db_connect.php';
header('Content-Type: text/html; charset=utf-8');

echo '<h2>Main DB ($conn)</h2>';
if (isset($conn) && !$conn->connect_error) {
    $res = $conn->query("SELECT DATABASE() as db");
    $dbName = $res ? $res->fetch_assoc()['db'] : 'unknown';
    echo "Connected to: <strong>" . htmlspecialchars($dbName) . "</strong><br>";
} else {
    echo 'Main DB connection failed: ' . ($conn->connect_error ?? 'unknown') . '<br>';
}

echo '<h2>pmed DB ($conn2)</h2>';
if (isset($conn2) && !$conn2->connect_error) {
    $res2 = $conn2->query("SELECT DATABASE() as db");
    $dbName2 = $res2 ? $res2->fetch_assoc()['db'] : 'unknown';
    echo "Connected to: <strong>" . htmlspecialchars($dbName2) . "</strong><br>";
    // quick row count
    $cnt = $conn2->query("SELECT COUNT(*) as c FROM pmed_documents");
    if ($cnt) {
        $rows = $cnt->fetch_assoc()['c'];
        echo "pmed_documents rows: <strong>".intval($rows)."</strong><br>";
    } else {
        echo "Could not query pmed_documents: " . htmlspecialchars($conn2->error) . "<br>";
    }
} else {
    echo 'pmed DB connection failed: ' . ($conn2->connect_error ?? 'unknown') . '<br>';
}

?>
