44 lines
688 B
PHP
44 lines
688 B
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use PDO;
|
|
use PDOException;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
class DatabaseConnection
|
|
{
|
|
private PDO $dbConnection;
|
|
|
|
public function __construct()
|
|
{
|
|
// get from config later
|
|
$dbHost = "localhost";
|
|
$dbPort = 3306;
|
|
$dbDatabase = "tfunix_db1";
|
|
$dbUser = "tfunix_db1";
|
|
$dbPassword = "aWeirder1";
|
|
|
|
try {
|
|
$this->dbConnection = new PDO(
|
|
dsn: "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase",
|
|
username: $dbUser,
|
|
password: $dbPassword
|
|
|
|
);
|
|
} catch (PDOException $exception) {
|
|
exit($exception->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @return \PDO
|
|
*/
|
|
public function getConnection(): PDO
|
|
{
|
|
return $this->dbConnection;
|
|
}
|
|
} |