Библиотека для cis, online, cms1
This commit is contained in:
commit
3c2e614d87
269 changed files with 39854 additions and 0 deletions
74
core/drivers/database.pgsql.php
Normal file
74
core/drivers/database.pgsql.php
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
require_once 'core/drivers/db.php';
|
||||
|
||||
/**
|
||||
* Ïðîñòîé êëàññ äëÿ ðàáîòû ñ áàçàìè äàííûõ
|
||||
*/
|
||||
class Database_PGSQL extends DB implements IDatabase
|
||||
{
|
||||
public function connect(array $dsn)
|
||||
{
|
||||
if (isset($dsn['port'])) {
|
||||
$port = "port={$dsn['port']}";
|
||||
} else {
|
||||
$port = "port=5432";
|
||||
}
|
||||
$str = "host={$dsn['hostspec']} $port dbname={$dsn['database']} user={$dsn['username']} password={$dsn['password']}";
|
||||
$db = @pg_connect($str)
|
||||
or die("Unable connect to database!");
|
||||
|
||||
return ($this->db = $db);
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
return pg_close($this->db);
|
||||
}
|
||||
|
||||
public function query($query)
|
||||
{
|
||||
$res = pg_query($this->db, $query)
|
||||
or die("Error: wrong SQL query #$query#");
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function fetchAllArray($query, $type = PGSQL_ASSOC)
|
||||
{
|
||||
$res = $this->query($query);
|
||||
|
||||
$rows = array();
|
||||
while ($row = pg_fetch_array($res, NULL, $type)) {
|
||||
$rows[] = $this->clean($row);
|
||||
}
|
||||
pg_free_result($res);
|
||||
return ($rows) ? $rows : array();
|
||||
}
|
||||
|
||||
public function affectedRows()
|
||||
{
|
||||
return pg_affected_rows($this->db);
|
||||
}
|
||||
|
||||
private function clean($row)
|
||||
{
|
||||
foreach ($row as $key => $value) {
|
||||
$row[$key] = trim($value);
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function fetchOneArray($query, $type = PGSQL_ASSOC)
|
||||
{
|
||||
$res = $this->query($query);
|
||||
$row = pg_fetch_array($res, NULL, $type);
|
||||
pg_free_result($res);
|
||||
return ($row) ? $this->clean($row) : array();
|
||||
}
|
||||
|
||||
function getNextId($seq)
|
||||
{
|
||||
$result = $this->fetchOneArray("SELECT nextval('$seq')");
|
||||
return $result['nextval'];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue