Project

General

Profile

Scripts » repair-all-tables.php

Επιδιόρθωση βάσης δεδομένων (σε PHP, για Windows και Unix/Linux) - Αλέξανδρος Διαμαντίδης, 27/02/2014 12:35

 
1
<?php
2

    
3
$USER = 'root';
4
$PASS = 'my-password';
5

    
6
set_time_limit(0);
7
$cli = (php_sapi_name() === 'cli' or defined('STDIN'));
8
if (!$cli) {
9
    header('Content-Type: text/plain');
10
    while (ob_get_level() > 0) {
11
        ob_end_flush();
12
    }
13
}
14

    
15
mysql_connect('localhost', $USER, $PASS);
16

    
17
$q = mysql_query('SHOW DATABASES');
18
while ($r = mysql_fetch_row($q)) {
19
    if ($r[0] == 'information_schema' or $r[0] == 'mysql') {
20
        continue;
21
    }
22
    echo "Repairing database: $r[0]\n";
23
    mysql_select_db($r[0]);
24
    $q1 = mysql_query('SHOW TABLES');
25
    while ($r1 = mysql_fetch_row($q1)) {
26
        $q2 = mysql_query('REPAIR TABLE ' . $r1[0]);
27
        while ($r2 = mysql_fetch_row($q2)) {
28
            echo "   ", implode(' ', $r2), "\n";
29
        }
30
    }
31
}
32

    
33
echo "\n\n*** Finished ***\n\n";
(2-2/5)