Add command to create database

This commit is contained in:
Tim
2021-09-19 20:39:10 +02:00
parent 2fd43ed717
commit 2e8469b11a
2 changed files with 56 additions and 0 deletions

View File

@ -25,4 +25,17 @@ class DatabaseManager
return $dbs;
}
public function createDatabase(string $name)
{
$dbs = $this->listDatabases();
if(in_array($name, $dbs)) {
throw new \Exception(sprintf('Database "%s" already exists', $name));
}
$result = $this->conn->query(sprintf('CREATE DATABASE `%s`', $name));
if (!$result) {
throw new \Exception(sprintf('Database create error: %s', $this->conn->error));
}
}
}