From b40783e8889b64f813c898ee2ce7e967582ef34e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 2 Dec 2013 18:27:03 +0100 Subject: Affiche la taille de la base de données MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/lib_rss.php | 15 +++++++++++++++ lib/minz/dao/Model_pdo.php | 10 ++++++++++ 2 files changed, 25 insertions(+) (limited to 'lib') diff --git a/lib/lib_rss.php b/lib/lib_rss.php index ea5a1ffd0..3e23f7542 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -47,6 +47,21 @@ function small_hash ($txt) { return strtr ($t, '+/', '-_'); } +function formatBytes($bytes, $precision = 2, $system = 'IEC') { + if ($system === 'IEC') { + $base = 1024; + $units = array('B', 'KiB', 'MiB', 'GiB', 'TiB'); + } elseif ($system === 'SI') { + $base = 1000; + $units = array('B', 'KB', 'MB', 'GB', 'TB'); + } + $bytes = max(intval($bytes), 0); + $pow = $bytes === 0 ? 0 : floor(log($bytes) / log($base)); + $pow = min($pow, count($units) - 1); + $bytes /= pow($base, $pow); + return round($bytes, $precision) . ' ' . $units[$pow]; +} + function timestamptodate ($t, $hour = true) { $month = Translate::t (date('M', $t)); if ($hour) { diff --git a/lib/minz/dao/Model_pdo.php b/lib/minz/dao/Model_pdo.php index 48c81d082..a93291fc8 100755 --- a/lib/minz/dao/Model_pdo.php +++ b/lib/minz/dao/Model_pdo.php @@ -80,6 +80,16 @@ class Model_pdo { public function rollBack() { $this->bd->rollBack(); } + + public function size() { + $db = Configuration::dataBase (); + $sql = 'SELECT SUM(data_length + index_length) FROM information_schema.TABLES WHERE table_schema = ?'; + $stm = $this->bd->prepare ($sql); + $values = array ($db['base']); + $stm->execute ($values); + $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0); + return $res[0]; + } } class FreshPDO extends PDO { -- cgit v1.2.3