<?php
// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Include database configuration
require_once __DIR__ . '/admin/database/db_config.php';
echo "<h1>Database Connection Test</h1>";
// Check if connection is successful
if ($conn) {
echo "<p style='color: green;'>Database connection successful!</p>";
// Check if required tables exist
$required_tables = [
'site_settings',
'courses',
'testimonials',
'students',
'institute_stats'
];
echo "<h2>Required Tables Check:</h2>";
echo "<ul>";
foreach ($required_tables as $table) {
$result = mysqli_query($conn, "SHOW TABLES LIKE '$table'");
if (mysqli_num_rows($result) > 0) {
echo "<li style='color: green;'>Table '$table' exists</li>";
// Check if table has data
$count_query = "SELECT COUNT(*) as count FROM $table";
$count_result = mysqli_query($conn, $count_query);
if ($count_result) {
$count = mysqli_fetch_assoc($count_result)['count'];
echo " - Contains $count records";
} else {
echo " - Error checking record count: " . mysqli_error($conn);
}
} else {
echo "<li style='color: red;'>Table '$table' does not exist</li>";
}
}
echo "</ul>";
// Create missing tables
echo "<h2>Creating Missing Tables:</h2>";
// Create site_settings table if it doesn't exist
$result = mysqli_query($conn, "SHOW TABLES LIKE 'site_settings'");
if (mysqli_num_rows($result) == 0) {
$sql = "CREATE TABLE site_settings (
id INT(11) NOT NULL AUTO_INCREMENT,
setting_key VARCHAR(100) NOT NULL,
setting_value TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY (setting_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
if (mysqli_query($conn, $sql)) {
echo "<p style='color: green;'>Table 'site_settings' created successfully</p>";
// Insert default settings
$default_settings = [
['site_name', 'Popular Computer'],
['site_tagline', 'Computer Education Institute'],
['site_logo', 'assets/img/logo.png'],
['primary_color', '#4e73df'],
['enable_animations', 'true'],
['contact_email', '[email protected]'],
['contact_phone', '+91 9876543210']
];
foreach ($default_settings as $setting) {
$insert_sql = "INSERT INTO site_settings (setting_key, setting_value) VALUES ('$setting[0]', '$setting[1]')";
if (mysqli_query($conn, $insert_sql)) {
echo "<p>Inserted setting: $setting[0]</p>";
} else {
echo "<p style='color: red;'>Error inserting setting $setting[0]: " . mysqli_error($conn) . "</p>";
}
}
} else {
echo "<p style='color: red;'>Error creating table 'site_settings': " . mysqli_error($conn) . "</p>";
}
}
// Create institute_stats table if it doesn't exist
$result = mysqli_query($conn, "SHOW TABLES LIKE 'institute_stats'");
if (mysqli_num_rows($result) == 0) {
$sql = "CREATE TABLE institute_stats (
id INT(11) NOT NULL AUTO_INCREMENT,
title VARCHAR(100) NOT NULL,
value INT(11) NOT NULL DEFAULT 0,
icon VARCHAR(50) NOT NULL,
is_visible TINYINT(1) NOT NULL DEFAULT 1,
display_order INT(11) NOT NULL DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
if (mysqli_query($conn, $sql)) {
echo "<p style='color: green;'>Table 'institute_stats' created successfully</p>";
// Insert default stats
$default_stats = [
['Students Trained', 5000, 'fa-user-graduate', 1, 1],
['Courses Offered', 25, 'fa-book', 1, 2],
['Certified Trainers', 15, 'fa-chalkboard-teacher', 1, 3],
['Years Experience', 18, 'fa-calendar-alt', 1, 4]
];
foreach ($default_stats as $stat) {
$insert_sql = "INSERT INTO institute_stats (title, value, icon, is_visible, display_order)
VALUES ('$stat[0]', $stat[1], '$stat[2]', $stat[3], $stat[4])";
if (mysqli_query($conn, $insert_sql)) {
echo "<p>Inserted stat: $stat[0]</p>";
} else {
echo "<p style='color: red;'>Error inserting stat $stat[0]: " . mysqli_error($conn) . "</p>";
}
}
} else {
echo "<p style='color: red;'>Error creating table 'institute_stats': " . mysqli_error($conn) . "</p>";
}
}
// Create students table if it doesn't exist
$result = mysqli_query($conn, "SHOW TABLES LIKE 'students'");
if (mysqli_num_rows($result) == 0) {
$sql = "CREATE TABLE students (
id INT(11) NOT NULL AUTO_INCREMENT,
full_name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL,
phone VARCHAR(20) NOT NULL,
password VARCHAR(255) NOT NULL,
profile_image VARCHAR(255) DEFAULT NULL,
status ENUM('active', 'inactive', 'suspended') NOT NULL DEFAULT 'active',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY (email)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
if (mysqli_query($conn, $sql)) {
echo "<p style='color: green;'>Table 'students' created successfully</p>";
} else {
echo "<p style='color: red;'>Error creating table 'students': " . mysqli_error($conn) . "</p>";
}
}
// Create courses table if it doesn't exist
$result = mysqli_query($conn, "SHOW TABLES LIKE 'courses'");
if (mysqli_num_rows($result) == 0) {
$sql = "CREATE TABLE courses (
id INT(11) NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
duration VARCHAR(50) NOT NULL,
price DECIMAL(10,2) NOT NULL,
image VARCHAR(255) DEFAULT NULL,
featured TINYINT(1) NOT NULL DEFAULT 0,
status ENUM('active', 'inactive') NOT NULL DEFAULT 'active',
students_count INT(11) NOT NULL DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
if (mysqli_query($conn, $sql)) {
echo "<p style='color: green;'>Table 'courses' created successfully</p>";
// Insert sample courses
$sample_courses = [
['Web Development', 'Learn HTML, CSS, JavaScript, PHP and MySQL to build dynamic websites.', '3 Months', 15000, 'assets/img/courses/web-development.jpg', 1, 'active', 120],
['Graphic Design', 'Master Adobe Photoshop, Illustrator and InDesign for print and digital media.', '2 Months', 12000, 'assets/img/courses/graphic-design.jpg', 1, 'active', 85],
['Office Automation', 'Learn Microsoft Office suite including Word, Excel, PowerPoint and Access.', '1 Month', 8000, 'assets/img/courses/office-automation.jpg', 0, 'active', 200]
];
foreach ($sample_courses as $course) {
$insert_sql = "INSERT INTO courses (title, description, duration, price, image, featured, status, students_count)
VALUES ('$course[0]', '$course[1]', '$course[2]', $course[3], '$course[4]', $course[5], '$course[6]', $course[7])";
if (mysqli_query($conn, $insert_sql)) {
echo "<p>Inserted course: $course[0]</p>";
} else {
echo "<p style='color: red;'>Error inserting course $course[0]: " . mysqli_error($conn) . "</p>";
}
}
} else {
echo "<p style='color: red;'>Error creating table 'courses': " . mysqli_error($conn) . "</p>";
}
}
// Create testimonials table if it doesn't exist
$result = mysqli_query($conn, "SHOW TABLES LIKE 'testimonials'");
if (mysqli_num_rows($result) == 0) {
$sql = "CREATE TABLE testimonials (
id INT(11) NOT NULL AUTO_INCREMENT,
student_id INT(11) NOT NULL,
content TEXT NOT NULL,
course_name VARCHAR(255) NOT NULL,
rating TINYINT(1) NOT NULL DEFAULT 5,
status ENUM('pending', 'approved', 'rejected') NOT NULL DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
if (mysqli_query($conn, $sql)) {
echo "<p style='color: green;'>Table 'testimonials' created successfully</p>";
} else {
echo "<p style='color: red;'>Error creating table 'testimonials': " . mysqli_error($conn) . "</p>";
}
}
} else {
echo "<p style='color: red;'>Database connection failed: " . mysqli_connect_error() . "</p>";
}
echo "<p><a href='index.php'>Go to Homepage</a></p>";
?>