Blog Test Sayfası'; echo '

Veritabanı Bağlantısı Test

'; if ($db) { echo '

Veritabanı bağlantısı başarılı

'; } else { echo '

Veritabanı bağlantısı başarısız

'; } echo '

Blog Tablosu Kontrolü

'; try { $table_check = $db->query("SHOW TABLES LIKE 'blog'"); $blog_table_exists = $table_check->rowCount() > 0; echo '

Blog tablosu ' . ($blog_table_exists ? 'mevcut' : 'mevcut değil') . '

'; if ($blog_table_exists) { $count_query = "SELECT COUNT(*) FROM blog"; $count_result = $db->query($count_query); $total_blog_count = $count_result->fetchColumn(); echo '

Toplam Blog Yazısı Sayısı: ' . $total_blog_count . '

'; // Blog tablosu yapısını göster $structure = $db->query("DESCRIBE blog"); echo '

Blog Tablosu Yapısı:

'; echo '
';
        while ($column = $structure->fetch(PDO::FETCH_ASSOC)) {
            print_r($column);
        }
        echo '
'; } } catch (PDOException $e) { echo '

Veritabanı Hatası: ' . $e->getMessage() . '

'; } echo '

Blog Yazıları

'; try { // Blog gönderilerini getir $query = "SELECT b.id, b.title, b.slug, b.summary, b.image, b.type, b.author_id, b.status, b.created_at, b.updated_at, u.username as author_name FROM blog b LEFT JOIN users u ON b.author_id = u.id ORDER BY b.created_at DESC LIMIT 10"; $stmt = $db->prepare($query); $stmt->execute(); $posts = $stmt->fetchAll(PDO::FETCH_ASSOC); if (empty($posts)) { echo '

Hiç blog yazısı bulunamadı

'; } else { echo ''; echo ''; foreach ($posts as $post) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
ID Başlık Slug Durum Resim Özet Yazar Tarih
' . $post['id'] . '' . htmlspecialchars($post['title']) . '' . htmlspecialchars($post['slug']) . '' . htmlspecialchars($post['status']) . '' . htmlspecialchars($post['image']) . '' . htmlspecialchars(mb_substr($post['summary'], 0, 100)) . '...' . htmlspecialchars($post['author_name'] ?? 'Belirtilmemiş') . '' . date('d.m.Y H:i', strtotime($post['created_at'])) . '
'; } } catch (PDOException $e) { echo '

Blog yazıları alınırken hata: ' . $e->getMessage() . '

'; }