connection + table 'test'
This commit is contained in:
parent
20e8243cb9
commit
b8e4a45ec7
@ -4,6 +4,7 @@ spl_autoload_register(function ($className) {
|
||||
// Définir les mappings des namespaces vers leurs répertoires de base
|
||||
$namespaceMap = [
|
||||
'Portfolio\\Configure\\Routing\\' => __DIR__ . '/../routing/',
|
||||
'Portfolio\\Configure\\Database\\' => __DIR__ . '/../database/',
|
||||
|
||||
'Portfolio\\Source\\Design\\Controller\\Home\\' => __DIR__ . '/../../source/design/controller/home/',
|
||||
'Portfolio\\Source\\Design\\Controller\\Home\\Read\\' => __DIR__ . '/../../source/design/controller/home/read',
|
||||
|
@ -1 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Portfolio\Configure\Database;
|
||||
|
||||
use PDO;
|
||||
|
||||
class connection
|
||||
{
|
||||
private $databaseName;
|
||||
private $databaseHost;
|
||||
private $databaseUsername;
|
||||
private $databasePassword;
|
||||
private $databasePdo;
|
||||
|
||||
public function __construct(string $databaseName, string $databaseHost, string $databaseUsername, string $databasePassword)
|
||||
{
|
||||
$this->databaseName = $databaseName;
|
||||
$this->databaseHost = $databaseHost;
|
||||
$this->databaseUsername = $databaseUsername;
|
||||
$this->databasePassword = $databasePassword;
|
||||
}
|
||||
|
||||
public function get_pdo(): PDO
|
||||
{
|
||||
if ($this->databasePdo === null) {
|
||||
$this->databasePdo = new PDO(
|
||||
"pgsql:host=localhost;port=5433;dbname=portfolio",
|
||||
$this->databaseUsername,
|
||||
$this->databasePassword,
|
||||
[
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return $this->databasePdo;
|
||||
}
|
||||
}
|
@ -2,12 +2,18 @@
|
||||
|
||||
namespace Portfolio\Source\Design\Controller\Home\Read;
|
||||
|
||||
use Portfolio\Configure\Database\Connection;
|
||||
use Portfolio\Source\Design\Controller\Base;
|
||||
|
||||
class Read extends Base
|
||||
{
|
||||
public function read(int $id)
|
||||
{
|
||||
$databaseConnection = new Connection('portfolio', '127.0.0.1', 'postgres', 'postgres');
|
||||
$requestDatabase = $databaseConnection->get_pdo()->query('SELECT * FROM Test');
|
||||
$test = $requestDatabase->fetchAll();
|
||||
var_dump($test);
|
||||
|
||||
return $this->show('home.read.read', ['id' => $id]);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user