You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
984 B

<?php
namespace app\core;
use PDO;
class Connection
{
private static PDO $instance;
public static function getInstance(): PDO|NULL
{
$cd = [];
if (empty(self::$instance)) {
$cd = [
'host_db' => 'postgres',
'porta_db' => '5432',
'base_db' => 'pbx',
'usuario' => 'contacte',
'senha' => 'ctepgSQL'
];
self::$instance = new PDO(
"pgsql:host={$cd['host_db']};port={$cd['porta_db']};dbname={$cd['base_db']}",
$cd['usuario'],
$cd['senha'],
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
PDO::ATTR_CASE => PDO::CASE_NATURAL
]
);
}
if (self::$instance) {
return self::$instance;
}
return null;
}
}