Thanks very much for the help on this, still not resolved.
Let me know if anything below helps...
There is this stuff:
<?php
class db_adapters_pgsql
{
var $name = '';
var $host = '';
var $user = '';
var $pass = '';
var $db_installed = TRUE;
var $installing = FALSE;
var $last_error = '';
var $showqueries = 0;
var $queries = 0;
var $querytext = '';
var $result = '';
var $error = FALSE;
var $lasterror = '';
var $lastquery = '';
var $p = '';
var $f = '';
function __construct($host, $db, $user, $pass, $installing = FALSE)
{
$this->host = $host;
$this->name = $db;
$this->user = $user;
$this->pass = $pass;
$this->installing = $installing;
if (!function_exists('pg_connect')) return $this->db_installed = FALSE;
if (!$this->installing) {
$this->connect();
$this->select();
}
$this->f = "<font size=\"-1\" face=\"verdana\">";
$this->querytext = "<table width=\"90%\" cellspacing=\"2\" border=\"1\"><tr><td colspan=\"3\" align=\"center\"><font size=\"+1\" face=\"verdana\">SQL Queries </font></td></tr><tr><td align=\"center\">{$this->f}#</td><td align=\"center\">{$this->f}Type</td><td>{$this->f}SQL</td></tr>";
}
function connect()
{
GLOBAL $dbresource;
if (!($dbresource = @pg_connect("host={$this->host} dbname={$this->name} user={$this->user} password={$this->pass}"))) {
if (!$this->installing) {
echo "Seir Anphin was unable to connect to the database at $this->host. <br><br>Reason: " . pg_last_error();
exit();
} else {
$this->last_error = "Could not connect to the database at $this->host. Reason: " . pg_last_error();
return FALSE;
}
}
return TRUE;
}
function select()
{
return TRUE;
}
function close()
{
return mysql_close();
}
// at least systems running php5 will get their table tag closed. it's important, sort of.
function __destruct()
{
$this->querytext .= "</table><br>";
}
function show_tables()
{
$this->query("SELECT relname FROM pg_stat_user_tables ORDER BY relname");
}
function insert($table, $fieldarr, $functions = '')
{
if ($functions != '') $functions = explode(',', $functions);
$fields = '';
$values = '';
foreach ($fieldarr as $k=>$v) {
if (is_array($functions)) {
foreach ($functions as $funcname) {
$v = $funcname($v);
}
}
$fields .= "$k, ";
$values .= "'$v', ";
}
$fields = substr($fields, 0, -2);
$values = substr($values, 0, -2);
$this->query("INSERT INTO {$this->p}$table ($fields) VALUES ($values)", FALSE);
}
function query($sql, $use_internal_result = TRUE)
{
GLOBAL $dbresource;
if ($use_internal_result) {
$this->result = pg_query($dbresource, $sql);
} else {
$result = pg_query($dbresource, $sql);
}
$this->queries++;
$this->lastquery = $sql;
if (pg_last_error() != '') {
$this->error = TRUE;
$this->lasterror = "Error in query $sql<br />" . pg_last_error();
$this->querytext.="<tr><td align=\"center\"><b>$this->queries</b></td><td align=\"center\"><font color=\"red\"><i>error</i> </font></td><td>$this->f".nl2br(htmlspecialchars($sql))."<br>MySQL error message: $this->lasterror </font></td></tr>";
trigger_error($this->lasterror);
//echo "<br><font size=\"-2\" face=\"verdana\">SQL Error, check the sql queries to find out what went wrong.";
return FALSE;
}
$this->querytext.="<tr><td align=\"center\"><b>$this->queries</b></td><td align=\"center\"><i>query</i></td><td>".nl2br(htmlspecialchars($sql))."</td></tr>";
if ($use_internal_result) {
return $this->result;
} else {
return $result;
}
}
// Returns FALSE if no results.
function result($sql)
{
$this->queries++;
$this->querytext.="<tr><td align=\"center\"><b>$this->queries</b></font> </td><td><i>result</i></td><td>$sql</td></tr>";
$result = pg_query($sql);
@pg_result_seek($result, 0);
$r_result = pg_fetch_row($result);
$r_result = $r_result[0];
if ($this->numrows($result) < 1) return FALSE;
if (is_string($result)) return stripslashes($r_result);
return $r_result;
}
function getarray($result = '', $type = PGSQL_ASSOC)
{
if (!empty($result)) {
return @pg_fetch_array($result, null, $type);
} else {
return @pg_fetch_array($this->result, null, $type);
}
}
function numrows($result = '')
{
if ($result != '') return @pg_num_rows($result);
return @pg_num_rows($this->result);
}
function affected_rows()
{
GLOBAL $dbresource;
return pg_affected_rows($dbresource);
}
function _insert_id($sequence) {
GLOBAL $dbresource;
$res = pg_query("SELECT currval('{$sequence}') AS currval");
if ($res) {
$rec = pg_fetch_assoc($res);
$insert_id = $rec['currval'];
return $insert_id;
} else {
trigger_error("PostgreSQL did not return the sequence currval, try using the $dba->insert_id(\$table, \$name function instead.");
}
}
function insert_id($table, $idname) {
#trigger_error("Error: the insert_id method was called when it is no longer supported.");
$id = $this->result("SELECT $idname FROM $table ORDER BY $idname DESC LIMIT 1");
return $id;
}
}
?>
and there is this stuff:
<?php
class baseDAO
{
public static function buildSQL(array $pvars, $functions = '', $syntax = 'COL_LIST')
{
if ($functions != '') $functions = explode(',', $functions);
$keys = '';
$values = '';
$string = '';
if (is_array($pvars)) {
foreach ($pvars as $key=>$val) {
if (is_array($functions)) {
foreach ($functions as $funcname) {
$val = $funcname($val);
}
}
// Generates the column-list syntax
if ($syntax == 'COL_LIST') {
$keys .= "$key, ";
$values .= "'$val', ";
// Generates a SET query
} else {
$string .= "$key='$val', ";
}
}
if ($syntax == 'COL_LIST') {
$keys = substr($keys, 0, -2);
$values = substr($values, 0, -2);
$string = "($keys) VALUES ($values)";
} else {
$string = "SET " . substr($string, 0, -2);
}
return $string;
} else {
trigger_error("Error: buildsql() expected an array.", E_ERROR);
return FALSE;
}
}
}
?>
And this
<?php
/**
* Data Access Object for prop_lists table
*/
class listingDAO extends baseDAO
{
public function load(lists $ui)
{
GLOBAL $dba;
$items = array();
$dba->query("SELECT * FROM prop_lists ORDER BY urlname ASC");
while (($a = $dba->getarray())) {
$ui->addRow($a);
}
return $items;
}
public function queryById($id)
{
GLOBAL $dba;
$dba->query("SELECT * FROM prop_lists WHERE listid=$id");
return $dba->getarray();
}
public function add($data)
{
GLOBAL $dba;
// Change dashes to underscores because submenues are classes
// and classes can't have dashes in them.
$data['submenuname'] = str_replace('-', '_', $data['submenuname']);
// Remove any file extensions from urlname
$data['urlname'] = str_replace('.php', '', $data['urlname']);
$data['urlname'] = str_replace('.ihtml', '', $data['urlname']);
$dba->query("INSERT INTO prop_lists ". $this->buildSQL($data, 'pg_escape_string'));
}
public function saveById($data, $id)
{
GLOBAL $dba;
$dba->query("UPDATE prop_lists ". $this->buildSQL($data, 'pg_escape_string', 'SET') . " WHERE listid=$id");
}
public function deleteById($id)
{
GLOBAL $dba;
$dba->query("DELETE FROM prop_lists WHERE listid=$id");
}
}
?>