php class Database extends PDO private static instance null private co

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
class Database extends PDO {
private static $instance = null;
private $connection;
private $host = 'localhost';
private $user = 'postgres';
private $password = '1234';
private $dbname = 'document';
private $port = '5432';
public function __construct() {
$this->connection = pg_pconnect("pgsql:host=$this->host;port=$this->port;dbname=$this->dbname;user=$this->user;password=$this->password");
if (!$this->connection) return false;
}
public static function getInstance() {
if(!self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
private function __clone() { }
public function getConnection() {
return $this->connection;
}
public function close() {
pg_close($this->connection);
}
}