diff --git a/app/src/Infrastructure/Api/Database/DatabaseHandlerInterface.php b/app/src/Infrastructure/Api/Database/DatabaseHandlerInterface.php index d14bfeb..f0a9c82 100644 --- a/app/src/Infrastructure/Api/Database/DatabaseHandlerInterface.php +++ b/app/src/Infrastructure/Api/Database/DatabaseHandlerInterface.php @@ -2,8 +2,6 @@ namespace Slovocast\Infrastructure\Api\Database; -use PDO; - interface DatabaseHandlerInterface { /** @@ -13,11 +11,14 @@ interface DatabaseHandlerInterface /** * Get the connection string required for establishing connections to the - * database + * database. */ - public function getDsn(): string; + public function getConnectionString(): string; /** + * Retrieve a results set from the database. If there are no results, opt + * for returning an empty array rather than throwing an Exception. + * * @param string $query * @param array $params Either a list of params of the KV params * @return array The results as an array, empty if no results @@ -25,6 +26,10 @@ interface DatabaseHandlerInterface public function query(string $query, array $params = []): array; /** + * Used for performing inserts, updates, deletes. We should expect the + * statement to either be successful or not - avoid throwing Exceptions + * here as well. + * * @param string $query * @param array $params Either a list of params, or the KV of params * @return bool True if successful diff --git a/app/src/Infrastructure/Database/DatabaseHandler.php b/app/src/Infrastructure/Database/DatabaseHandler.php index 7e0b5c5..a903239 100644 --- a/app/src/Infrastructure/Database/DatabaseHandler.php +++ b/app/src/Infrastructure/Database/DatabaseHandler.php @@ -16,7 +16,11 @@ class DatabaseHandler implements DatabaseHandlerInterface private string $database, private int $port = 3306 ) { - $this->pdo = new PDO($this->getDsn(), $username, $password); + $this->pdo = new PDO( + $this->getConnectionString(), + $username, + $password + ); } /** @@ -27,7 +31,7 @@ class DatabaseHandler implements DatabaseHandlerInterface return $this->pdo; } - public function getDsn(): string + public function getConnectionString(): string { return "mysql:dbname={$this->database};host={$this->host};port={$this->port}"; }