dbmanager/src/Service/MysqliConnection.php
2022-09-28 13:34:03 +02:00

24 lines
559 B
PHP

<?php
namespace App\Service;
use Exception;
use mysqli;
class MysqliConnection
{
private mysqli $connection;
public function __construct(DatabaseCredentials $credentials)
{
$this->connection = new mysqli($credentials->getHostname(), $credentials->getUser(), $credentials->getPassword());
if ($this->connection->connect_error) {
throw new Exception("Connection failed: " . $this->connection->connect_error);
}
}
public function getConnection(): mysqli
{
return $this->connection;
}
}