-
Notifications
You must be signed in to change notification settings - Fork 0
/
optimize.php
48 lines (37 loc) · 1.28 KB
/
optimize.php
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
<?php
require_once 'settings.php';
header("Content-Type: text/html; charset=UTF-8");
$conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
if ($conn->connect_error) {
die('<p>Connection failed: ' . htmlspecialchars($conn->connect_error) . '</p>');
}
echo "<h2>Table Optimization and Repair</h2>";
// Fetch all table names from the database
$result = $conn->query("SHOW TABLES");
if (!$result) {
die('<p>Error fetching tables: ' . htmlspecialchars($conn->error) . '</p>');
}
$tables = [];
while ($row = $result->fetch_array()) {
$tables[] = $row[0];
}
foreach ($tables as $table) {
echo "<h3>Processing Table: $table</h3>";
// Check and repair table
$repair = $conn->query("REPAIR TABLE `$table`");
if ($repair) {
$msg = $repair->fetch_assoc();
echo "<p>Repair Status: " . $msg['Msg_text'] . "</p>";
} else {
echo "<p>Error repairing table $table: " . htmlspecialchars($conn->error) . "</p>";
}
// Optimize table
$optimize = $conn->query("OPTIMIZE TABLE `$table`");
if ($optimize) {
$msg = $optimize->fetch_assoc();
echo "<p>Optimize Status: " . $msg['Msg_text'] . "</p>";
} else {
echo "<p>Error optimizing table $table: " . htmlspecialchars($conn->error) . "</p>";
}
}
$conn->close();