-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-db.php
More file actions
69 lines (57 loc) · 2.06 KB
/
Copy pathtest-db.php
File metadata and controls
69 lines (57 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
header('Content-Type: application/json');
// Test database connection
try {
require_once 'includes/Database.php';
$db = Database::getInstance()->getConnection();
// Test connection
$db->query('SELECT 1');
// Get database info
$database = $db->query('SELECT DATABASE() as dbname')->fetch(PDO::FETCH_ASSOC)['dbname'];
$tables = $db->query('SHOW TABLES')->fetchAll(PDO::FETCH_COLUMN);
// Check if announcements table exists
$announcementsTable = in_array('announcements', $tables);
$announcementsData = [];
if ($announcementsTable) {
// Get table structure
$structure = $db->query('DESCRIBE announcements')->fetchAll(PDO::FETCH_ASSOC);
// Get some sample data
$announcementsData = [
'structure' => $structure,
'count' => $db->query('SELECT COUNT(*) as count FROM announcements')->fetch(PDO::FETCH_ASSOC)['count'],
'sample' => $db->query('SELECT * FROM announcements ORDER BY created_at DESC LIMIT 3')->fetchAll(PDO::FETCH_ASSOC)
];
}
// Check admin_users table
$adminUsersTable = in_array('admin_users', $tables);
$adminUsersData = [];
if ($adminUsersTable) {
$adminUsersData = [
'count' => $db->query('SELECT COUNT(*) as count FROM admin_users')->fetch(PDO::FETCH_ASSOC)['count']
];
}
// Return results
echo json_encode([
'success' => true,
'database' => $database,
'tables' => $tables,
'announcements' => [
'exists' => $announcementsTable,
'data' => $announcementsData
],
'admin_users' => [
'exists' => $adminUsersTable,
'data' => $adminUsersData
]
], JSON_PRETTY_PRINT);
} catch (Exception $e) {
http_response_code(500);
echo json_encode([
'success' => false,
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString()
], JSON_PRETTY_PRINT);
}