dbmaint.php
996 Bytes
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
<?php
require_once('../config/dmsDefaults.php');
print _kt('DB Maintenance') . "...\n\n";
$action = 'check';
$sqlaction = 'check table';
if ($argc > 0)
{
foreach($argv as $arg)
{
$arg=strtolower($arg);
switch ($arg)
{
case 'check':
case 'repair':
case 'optimize':
$sqlaction="$arg table";
$action = $arg;
break;
case 'help':
print "Usage: dbmaint.php repair|check|optimize\n";
exit;
}
}
}
print '* ' . sprintf(_kt("Action selected: %s"), $action) . "\n\n";
$sql = "show tables";
$tables = DBUtil::getResultArray($sql);
foreach($tables as $table)
{
$key = array_keys($table);
$tablename=$table[$key[0]];
$sql = "$sqlaction $tablename";
$result = DBUtil::getOneResult($sql);
if (PEAR::isError($result))
{
print sprintf(_kt("Attempted: %s"), $sql) . "\n";
print sprintf(_kt(' *: %s'), $result->getMessage()) . "\n";
continue;
}
print sprintf(_kt("Running: %s - %s"), $sql, $result['Msg_text']) . "\n";
}
print _kt('Done.') . "\n";
?>