# rvg-optimize-database/4.1/classes/odb-utilities.php

Optimize Database after Deleting Revisions, version 4.1. 67 lines.

- Page: https://pluginprobe.com/plugins/rvg-optimize-database/4.1/code/classes/odb-utilities.php
- Raw: https://pluginprobe.com/plugins/rvg-optimize-database/4.1/raw/classes/odb-utilities.php
- Modified: 2016-01-14T15:55:26+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/rvg-optimize-database/4.1/code/classes/odb-utilities.php#L10-L20`.

```php
<?php
/************************************************************************************************
 *
 *	UTILITIES
 *
 ************************************************************************************************/
?>
<?php
class ODB_Utilities
{
	/********************************************************************************************
	 *	CONSTRUCTOR
	 ********************************************************************************************/	
    function __construct()
    {
	} // __construct()


	/********************************************************************************************
	 *	FORMAT SIZES FROM BYTES TO KB OR MB
	 ********************************************************************************************/
	function odb_format_size($size, $precision=1)
	{
		if($size > 1024*1024) return (round($size/(1024*1024),$precision)).' MB';
		
		return (round($size/1024,$precision)).' KB';
	} // odb_format_size()
	

	/********************************************************************************************
	 *	CALCULATE THE SIZE OF THE WORDPRESS DATABASE (IN BYTES)
	 ********************************************************************************************/
	function odb_get_db_size()
	{
		global $wpdb;
	
		$sql = sprintf("
		  SELECT SUM(data_length + index_length) AS size
			FROM information_schema.TABLES
		   WHERE table_schema = '%s'
		GROUP BY table_schema
		", DB_NAME);	
		
		$res = $wpdb->get_results($sql);
		
		return $res[0]->size;
	} // odb_get_db_size()

	
	/********************************************************************************************
	 *	GET DATABASE TABLES
	 ********************************************************************************************/
	function odb_get_tables()
	{
		global $wpdb;

		$sql = sprintf("
         SHOW FULL TABLES
		 FROM `%s`
		WHERE table_type = 'BASE TABLE'		
		", DB_NAME);		
		
		// GET THE DATABASE BASE TABLES
		return $wpdb->get_results($sql, ARRAY_N);
	} // odb_get_tables()
	
} // ODB_Utilities
```
