PluginProbe
Optimize Database after Deleting Revisions / 4.1
Optimize Database after Deleting Revisions v4.1
3.4.7 3.4.8 3.4.9 3.5 3.5.1 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.3 All 144 releases
rvg-optimize-database / classes / odb-utilities.php

odb-utilities.php in Optimize Database after Deleting Revisions 4.1, at classes/odb-utilities.php

67 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /************************************************************************************************
3 *
4 * UTILITIES
5 *
6 ************************************************************************************************/
7 ?>
8 <?php
9 class ODB_Utilities
10 {
11 /********************************************************************************************
12 * CONSTRUCTOR
13 ********************************************************************************************/
14 function __construct()
15 {
16 } // __construct()
17
18
19 /********************************************************************************************
20 * FORMAT SIZES FROM BYTES TO KB OR MB
21 ********************************************************************************************/
22 function odb_format_size($size, $precision=1)
23 {
24 if($size > 1024*1024) return (round($size/(1024*1024),$precision)).' MB';
25
26 return (round($size/1024,$precision)).' KB';
27 } // odb_format_size()
28
29
30 /********************************************************************************************
31 * CALCULATE THE SIZE OF THE WORDPRESS DATABASE (IN BYTES)
32 ********************************************************************************************/
33 function odb_get_db_size()
34 {
35 global $wpdb;
36
37 $sql = sprintf("
38 SELECT SUM(data_length + index_length) AS size
39 FROM information_schema.TABLES
40 WHERE table_schema = '%s'
41 GROUP BY table_schema
42 ", DB_NAME);
43
44 $res = $wpdb->get_results($sql);
45
46 return $res[0]->size;
47 } // odb_get_db_size()
48
49
50 /********************************************************************************************
51 * GET DATABASE TABLES
52 ********************************************************************************************/
53 function odb_get_tables()
54 {
55 global $wpdb;
56
57 $sql = sprintf("
58 SHOW FULL TABLES
59 FROM `%s`
60 WHERE table_type = 'BASE TABLE'
61 ", DB_NAME);
62
63 // GET THE DATABASE BASE TABLES
64 return $wpdb->get_results($sql, ARRAY_N);
65 } // odb_get_tables()
66
67 } // ODB_Utilities