24 lines
559 B
PHP
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;
|
|
}
|
|
} |