diff --git a/system/Commands/Database/ShowTableInfo.php b/system/Commands/Database/ShowTableInfo.php index 07aa60c961ca..92fde73aed28 100644 --- a/system/Commands/Database/ShowTableInfo.php +++ b/system/Commands/Database/ShowTableInfo.php @@ -102,6 +102,8 @@ public function run(array $params) $this->db = Database::connect(); $this->DBPrefix = $this->db->getPrefix(); + $this->showDBConfig(); + $tables = $this->db->listTables(); if (array_key_exists('desc', $params)) { @@ -145,6 +147,22 @@ public function run(array $params) $this->showDataOfTable($tableName, $limitRows, $limitFieldValue); } + private function showDBConfig(): void + { + $data = [[ + 'hostname' => $this->db->hostname, + 'database' => $this->db->getDatabase(), + 'username' => $this->db->username, + 'DBDriver' => $this->db->getPlatform(), + 'DBPrefix' => $this->DBPrefix, + 'port' => $this->db->port, + ]]; + CLI::table( + $data, + ['hostname', 'database', 'username', 'DBDriver', 'DBPrefix', 'port'] + ); + } + private function removeDBPrefix(): void { $this->db->setPrefix(''); diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 83303fea963d..6d92965f0b94 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -45,6 +45,7 @@ * @property int $transDepth * @property bool $transFailure * @property bool $transStatus + * @property string $username * * @template TConnection * @template TResult diff --git a/tests/system/Commands/Database/ShowTableInfoTest.php b/tests/system/Commands/Database/ShowTableInfoTest.php index be52a71b2991..9b54ff2acf9e 100644 --- a/tests/system/Commands/Database/ShowTableInfoTest.php +++ b/tests/system/Commands/Database/ShowTableInfoTest.php @@ -64,6 +64,16 @@ public function testDbTable(): void $this->assertMatchesRegularExpression($expectedPattern, $result); } + public function testDbTableShowsDBConfig(): void + { + command('db:table'); + + $result = $this->getNormalizedResult(); + + $expectedPattern = '/\| hostname[[:blank:]]+\| database[[:blank:]]+\| username[[:blank:]]+\| DBDriver[[:blank:]]+\| DBPrefix[[:blank:]]+\| port[[:blank:]]+\|/'; + $this->assertMatchesRegularExpression($expectedPattern, $result); + } + public function testDbTableShow(): void { command('db:table --show');