Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1277 → Rev 1278

/astrisk-stats/includes/db/postgresql.php
0,0 → 1,102
<?php
####################################################
# AstWeb - Asterisk PBX Dynamic config environment #
# #
# Written by: Jamie Carl #
# jazz@funkynerd.com #
# #
# Copyright (C) 2006 Achieve Corp #
# #
# Licence: This software is licenced under the #
# GNU/GPL. Please see licence.txt for #
# more information. #
####################################################
 
if ( !defined('IN_ASTWEB') ) {
die("Hacking attempt");
}
 
class db_obj {
private $connection;
private $result;
private $row;
function __construct($host, $user, $password, $database) {
$this->connection = pg_connect('host='.$host.' user='.$user.' password='.$password.' dbname='.$database) or
die("SQL service unavailable please try again later");
}
 
function __destruct() {
if($this->connection) {
pg_close($this->connection);
}
}
 
function query($sql) {
if($this->connection) {
$this->result = pg_query($this->connection, $sql) or die('Query failed: '.$sql);
return $this->result;
}
return false;
}
 
function query_params($sql, $params) {
if($this->connection) {
$this->result = pg_query_params($this->connection, $sql, $params)
or die('Query failed: '.$sql);
return $this->result;
}
return false;
}
 
function fetch_row() {
if($this->result) {
$this->row = pg_fetch_assoc($this->result);
return $this->row;
}
return false;
}
 
function fetch_row_idx() {
if($this->result) {
$this->row = pg_fetch_row($this->result);
return $this->row;
}
return false;
}
 
function fetch_all() {
if($this->result) {
return pg_fetch_all($this->result);
}
return false;
}
 
function num_rows() {
if($this->result) {
return pg_num_rows($this->result);
}
 
return 0;
}
 
function num_fields() {
if($this->result) {
return pg_num_fields($this->result);
}
}
 
function get_field_name($col) {
if($this->result) {
return pg_field_name($this->result, $col);
}
}
 
function get_field($col) {
if($this->row) {
return $this->row[$col];
}
return NULL;
}
}
?>