<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once 'db_config.php';

$db = $conn;  // Use the connection from db_config.php

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

echo "Connected successfully!\n\n";

// Check available tables
echo "=== Available Tables ===\n";
$result = $db->query("SHOW TABLES");
if ($result) {
    $tables = [];
    while ($row = $result->fetch_row()) {
        $tables[] = $row[0];
        echo "- " . $row[0] . "\n";
    }
    echo "\n";
    
    // Try to load products from different sources
    echo "=== Checking Products Data ===\n";
    
    // Try blogs table
    if (in_array('blogs', $tables)) {
        $count = $db->query("SELECT COUNT(*) as cnt FROM blogs")->fetch_assoc()['cnt'];
        echo "blogs table: $count rows\n";
        
        $first = $db->query("SELECT id, title, description FROM blogs LIMIT 3");
        if ($first) {
            echo "Sample blogs:\n";
            while ($row = $first->fetch_assoc()) {
                echo "  ID: {$row['id']}, Title: {$row['title']}\n";
            }
        }
    }
    
    // Try products table
    if (in_array('products', $tables)) {
        $count = $db->query("SELECT COUNT(*) as cnt FROM products")->fetch_assoc()['cnt'];
        echo "products table: $count rows\n";
    }
    
    // Check seo_meta_tags
    if (in_array('seo_meta_tags', $tables)) {
        $count = $db->query("SELECT COUNT(*) as cnt FROM seo_meta_tags")->fetch_assoc()['cnt'];
        echo "seo_meta_tags table: $count rows\n";
    } else {
        echo "seo_meta_tags table does not exist\n";
    }
    
} else {
    echo "Error getting tables: " . $db->error . "\n";
}

$db->close();
?>
