Add list users command

This commit is contained in:
Tim
2021-09-19 21:12:09 +02:00
parent 2e8469b11a
commit d78f52b965
4 changed files with 54 additions and 8 deletions

View File

@ -29,7 +29,7 @@ class DatabaseManager
public function createDatabase(string $name)
{
$dbs = $this->listDatabases();
if(in_array($name, $dbs)) {
if (in_array($name, $dbs)) {
throw new \Exception(sprintf('Database "%s" already exists', $name));
}
@ -38,4 +38,20 @@ class DatabaseManager
throw new \Exception(sprintf('Database create error: %s', $this->conn->error));
}
}
public function listUsers(): array
{
$results = $this->conn->query('select * from mysql.user');
$users = [];
while ($result = $results->fetch_object()) {
$users[] = [
'name' => $result->User,
'host' => $result->Host,
'plugin' => $result->plugin,
];
}
return $users;
}
}