<?php
$conn = new mysqli("localhost", "root", "", "paycodex_codex");

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

echo "<h3>Checking users table</h3>";

// Check table status
$result = $conn->query("SHOW TABLE STATUS WHERE Name = 'users'");
if ($result && $row = $result->fetch_assoc()) {
    echo "Table Engine: " . $row['Engine'] . "<br>";
    echo "Table Rows: " . $row['Rows'] . "<br>";
    echo "Table Comment: " . $row['Comment'] . "<br><br>";
}

// Try to repair the table
echo "<h3>Attempting to repair table...</h3>";
$repair = $conn->query("REPAIR TABLE users");
if ($repair) {
    while ($row = $repair->fetch_assoc()) {
        echo "Msg_type: " . $row['Msg_type'] . " - Msg_text: " . $row['Msg_text'] . "<br>";
    }
}

echo "<br><h3>Testing SELECT query...</h3>";
$test = $conn->query("SELECT COUNT(*) as count FROM users");
if ($test) {
    $row = $test->fetch_assoc();
    echo "Total users in table: " . $row['count'] . "<br>";
} else {
    echo "Error: " . $conn->error . "<br>";
}

// Try selecting one user
echo "<br><h3>Testing SELECT with WHERE...</h3>";
$test2 = $conn->query("SELECT id, mobile FROM users LIMIT 1");
if ($test2 && $test2->num_rows > 0) {
    $row = $test2->fetch_assoc();
    echo "Sample user - ID: " . $row['id'] . ", Mobile: " . $row['mobile'] . "<br>";
} else {
    echo "Error or no users: " . $conn->error . "<br>";
}
?>
