/
DbPgsql.php
44 lines (37 loc) · 1018 Bytes
/
DbPgsql.php
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
43
44
<?php
class DbPgsql extends DbConnection
{
private $connectionString;
private $connection;
public function init()
{
// create the connection string
$connString = 'dbname=' . $this->params['database'];
$connString .= ' user=' . $this->params['username'];
if(isset($params['host']))
$connString .= ' host=' . $this->params['host'];
if(isset($params['port']))
$connString .= ' port=' . $this->params['port'];
$this->connectionString = $connString;
}
public function getRequireds()
{
return array('database', 'username');
}
function escapeString($string)
{
return "'" . pg_escape_string($this->connection, $string) . "'";
}
function _query($sql)
{
// lazy connection to the database
if(!$this->connection)
$this->connection = pg_connect($this->connectionString, PGSQL_CONNECT_FORCE_NEW);
$result = pg_query($this->connection, $sql);
return new DbPgResult($result);
}
function getLastInsertId()
{
return $this->fetchCell("select lastval()", array());
}
}