Start on project with the connection services and first command to list databases
This commit is contained in:
23
src/Service/MysqliConnection.php
Normal file
23
src/Service/MysqliConnection.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use mysqli;
|
||||
|
||||
class MysqliConnection
|
||||
{
|
||||
private mysqli $connection;
|
||||
|
||||
public function __construct($hostname, $user, $password)
|
||||
{
|
||||
$this->connection = new mysqli($hostname, $user, $password);
|
||||
if ($this->connection->connect_error) {
|
||||
throw new \Exception("Connection failed: " . $this->connection->connect_error);
|
||||
}
|
||||
}
|
||||
|
||||
public function getConnection(): mysqli
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user