common::getDatabaseSize PHP Method

getDatabaseSize() public method

Get the size of the database.
public getDatabaseSize ( $measurment = "" )
    function getDatabaseSize($measurment = "")
    {
        require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "settings.class.php";
        $settings = new settings();
        if ($settings::db_driver == "sqlite") {
            $databaseSize = filesize($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "portal.sqlite");
        } elseif ($settings::db_driver == "mysql") {
            $dbh = $this->pdoOpen();
            $sql = "SHOW TABLE STATUS";
            $sth = $dbh->prepare($sql);
            $sth->execute();
            $databaseSize = $sth->fetch(PDO::FETCH_ASSOC)["Data_length"];
            $sth = NULL;
            $dbh = NULL;
        } else {
            $databaseSize = 0;
        }
        switch ($measurment) {
            case "kb":
                return round($databaseSize / 1024, 2);
                break;
            case "mb":
                return round($databaseSize / 1024 / 1024, 2);
                break;
            case "gb":
                return round($databaseSize / 1024 / 1024 / 1024, 2);
                break;
            case "tb":
                return round($databaseSize / 1024 / 1024 / 1024 / 1024, 2);
                break;
            default:
                return $databaseSize;
        }
    }

Usage Example

Ejemplo n.º 1
0
">
                                    <input type="radio" name="networkInterface" id="metric" value="wlan0" autocomplete="off"<?php 
$networkInterface == "wlan0" ? print ' checked' : '';
?>
> wlan0
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
                <div role="tabpanel" class="tab-pane fade" id="maintenance">
                    <div class="panel panel-default">
                        <div class="panel-heading">Purge Positions</div>
                        <div class="panel-body">
                            <p>Current Database Size: <?php 
echo $common->getDatabaseSize("mb");
?>
MB</p>
                            <div class="form-group">
                                <label for="purgepositionspicker">Purge flight positions old than...</label><br />
                                <input type="text" class="form-control" id="purgepositionspicker" name="purgepositionspicker" autocomplete="off" <?php 
$settings::db_driver == "xml" ? print ' disabled' : '';
?>
>
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="purgepositions" value="purge"<?php 
$settings::db_driver == "xml" ? print ' disabled' : '';
?>
> Check to confirm purge of data.