Files
web_work/debug_db.php
2025-12-16 01:28:06 +03:00

55 lines
2.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// debug_db.php
require_once 'config/database.php';
$db = Database::getInstance()->getConnection();
echo "<h2>Проверка базы данных:</h2>";
// Проверка таблиц
$tables = ['users', 'categories', 'products', 'orders', 'order_items', 'cart'];
foreach ($tables as $table) {
try {
$result = $db->query("SELECT COUNT(*) FROM $table")->fetchColumn();
echo "✅ Таблица '$table': $result записей<br>";
} catch (Exception $e) {
echo "❌ Таблица '$table': НЕ СУЩЕСТВУЕТ<br>";
}
}
echo "<h2>Содержимое таблиц:</h2>";
// Показать категории
echo "<h3>Категории:</h3>";
try {
$categories = $db->query("SELECT * FROM categories")->fetchAll();
if (empty($categories)) {
echo "Категорий нет!<br>";
} else {
echo "<table border='1'><tr><th>ID</th><th>Название</th><th>Slug</th><th>Родитель</th></tr>";
foreach ($categories as $cat) {
echo "<tr><td>{$cat['category_id']}</td><td>{$cat['name']}</td><td>{$cat['slug']}</td><td>{$cat['parent_id']}</td></tr>";
}
echo "</table>";
}
} catch (Exception $e) {
echo "Ошибка: " . $e->getMessage();
}
// Показать товары
echo "<h3>Товары:</h3>";
try {
$products = $db->query("SELECT * FROM products")->fetchAll();
if (empty($products)) {
echo "Товаров нет!<br>";
} else {
echo "<table border='1'><tr><th>ID</th><th>Название</th><th>Цена</th><th>Категория</th><th>Статус</th></tr>";
foreach ($products as $product) {
echo "<tr><td>{$product['product_id']}</td><td>{$product['name']}</td><td>{$product['price']}</td><td>{$product['category_id']}</td><td>" . ($product['is_available'] ? 'Активен' : 'Неактивен') . "</td></tr>";
}
echo "</table>";
}
} catch (Exception $e) {
echo "Ошибка: " . $e->getMessage();
}
?>