DbConnectionAdapterPgsql.php
1.1 KB
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
45
46
<?php
class LtDbConnectionAdapterPgsql implements LtDbConnectionAdapter
{
public function connect($connConf)
{
if (isset($connConf['pconnect']) && true == $connConf['pconnect'])
{
$func = 'pg_pconnect';
}
else
{
$func = 'pg_connect';
}
return $func("host={$connConf['host']} port={$connConf['port']} user={$connConf['username']} password={$connConf['password']}");
}
public function exec($sql, $connResource)
{
$result = pg_query($connResource, $sql);
return pg_affected_rows($result);
}
public function query($sql, $connResource)
{
$result = pg_query($connResource, $sql);
return pg_fetch_all($result);
}
// SELECT CURRVAL(
// pg_get_serial_sequence('my_tbl_name','id_col_name'));"
// ------------------------------------------------------
// CREATE FUNCTION last_insert_id() RETURNS bigint AS $$
// SELECT lastval();
// $$ LANGUAGE SQL VOLATILE;
public function lastInsertId($connResource)
{
$result = pg_query($connResource, "SELECT lastval()");
$row = pg_fetch_array($result, 0, PGSQL_NUM);
return $row[0];
}
public function escape($sql, $connResource)
{
return pg_escape_string($sql);
}
}