helper_dbtool.php
1.74 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
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: helper_dbtool.php 31034 2012-07-11 04:03:30Z zhangjie $
*/
if (!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class helper_dbtool {
public static function dbversion() {
return DB::result_first("SELECT VERSION()");
}
public static function dbsize() {
$dbsize = 0;
$query = DB::query("SHOW TABLE STATUS LIKE '".getglobal('config/db/1/tablepre')."%'", 'SILENT');
while($table = DB::fetch($query)) {
$dbsize += $table['Data_length'] + $table['Index_length'];
}
return $dbsize;
}
public static function gettablestatus($tablename, $formatsize = true) {
$status = DB::fetch_first("SHOW TABLE STATUS LIKE '".str_replace('_', '\_', $tablename)."'");
if($formatsize) {
$status['Data_length'] = sizecount($status['Data_length']);
$status['Index_length'] = sizecount($status['Index_length']);
}
return $status;
}
public static function showtablecloumn($tablename) {
$data = array();
$db = &DB::object();
if($db->version() > '4.1') {
$query = $db->query("SHOW FULL COLUMNS FROM ".DB::table($tablename), 'SILENT');
} else {
$query = $db->query("SHOW COLUMNS FROM ".DB::table($tablename), 'SILENT');
}
while($field = @DB::fetch($query)) {
$data[$field['Field']] = $field;
}
return $data;
}
public static function isexisttable($tablename) {
$tablearr = array();
$query = DB::query('SHOW TABLES', 'SILENT');
while($table = DB::fetch($query)) {
foreach($table as $value) {
$tablearr[] = $value;
}
}
if(in_array(DB::table($tablename), $tablearr)) {
return true;
} else {
return false;
}
}
}
?>