| 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) |
| 25 |
$table_size = (round($size/(1024*1024),$precision)).' MB'; |
| 26 |
else |
| 27 |
$table_size = (round($size/1024,$precision)).' KB'; |
| 28 |
|
| 29 |
return $table_size; |
| 30 |
} // odb_format_size() |
| 31 |
|
| 32 |
|
| 33 |
/******************************************************************************************** |
| 34 |
* CALCULATE THE SIZE OF THE WORDPRESS DATABASE (IN BYTES) |
| 35 |
********************************************************************************************/ |
| 36 |
function odb_get_db_size() |
| 37 |
{ |
| 38 |
global $wpdb; |
| 39 |
|
| 40 |
$sql = " |
| 41 |
SELECT SUM(data_length + index_length) AS size |
| 42 |
FROM information_schema.TABLES |
| 43 |
WHERE table_schema = '".DB_NAME."' |
| 44 |
GROUP BY table_schema |
| 45 |
"; |
| 46 |
|
| 47 |
$res = $wpdb->get_results($sql); |
| 48 |
|
| 49 |
return $res[0]->size; |
| 50 |
} // odb_get_db_size() |
| 51 |
|
| 52 |
|
| 53 |
/******************************************************************************************** |
| 54 |
* GET DATABASE TABLES |
| 55 |
********************************************************************************************/ |
| 56 |
function odb_get_tables() |
| 57 |
{ |
| 58 |
global $wpdb; |
| 59 |
|
| 60 |
$sql = " |
| 61 |
SHOW FULL TABLES |
| 62 |
FROM `".DB_NAME."` |
| 63 |
WHERE table_type = 'BASE TABLE' |
| 64 |
"; |
| 65 |
|
| 66 |
// GET THE DATABASE BASE TABLES |
| 67 |
// $odb_class->odb_tables = $wpdb->get_results($sql, ARRAY_N); |
| 68 |
// var_dump($wpdb->get_results($sql, ARRAY_N)); |
| 69 |
return $wpdb->get_results($sql, ARRAY_N); |
| 70 |
} // odb_get_tables() |
| 71 |
} // ODB_Utilities |