<?php
// DB config include karo
include('/home/linkshub/public_html/links/config/db.php');

// Connect karo - common variable names try karta hoon
$host = $host ?? $db_host ?? $hostname ?? 'localhost';
$user = $user ?? $db_user ?? $username ?? 'linkshub_fundbna';
$pass = $pass ?? $db_pass ?? $password ?? '9At^W2})OkY{';
$name = $name ?? $db_name ?? $database ?? 'linkshub_fundb';

$conn = mysqli_connect($host, $user, $pass, $name);

if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

// Saare tables dekho pehle
$tables_result = mysqli_query($conn, "SHOW TABLES");
$tables = [];
while($row = mysqli_fetch_array($tables_result)) {
    $tables[] = $row[0];
}

echo "<h2>Tables in DB:</h2><pre>";
print_r($tables);
echo "</pre>";

// Common table names mein drivehub search karo
$search_tables = ['links', 'posts', 'urls', 'data', 'records'];

foreach($tables as $table) {
    // Columns dekho
    $cols_result = mysqli_query($conn, "SHOW COLUMNS FROM `$table`");
    $cols = [];
    while($col = mysqli_fetch_array($cols_result)) {
        $cols[] = $col[0];
    }
    
    // Agar koi url/link/domain column ho
    foreach($cols as $col) {
        if(in_array(strtolower($col), ['url', 'link', 'domain', 'host', 'redirect', 'source'])) {
            $q = mysqli_query($conn, "SELECT DISTINCT `$col` FROM `$table` WHERE `$col` LIKE '%drivehub%' LIMIT 100");
            if($q && mysqli_num_rows($q) > 0) {
                echo "<h3>Table: $table | Column: $col</h3><ul>";
                while($r = mysqli_fetch_array($q)) {
                    echo "<li>" . htmlspecialchars($r[$col]) . "</li>";
                }
                echo "</ul>";
            }
        }
    }
}

mysqli_close($conn);
echo "<p>Done!</p>";
?>