$title
Posted " . date("jS F Y", $date) . " by $publicname
$blurb

\n"; } ?> query("SELECT $valuefield, $captionfield FROM $table;"); # should be templatised? while ($db->next_record()) { if ($db->f($valuefield) == $selectedvalue) { $return .= sprintf("\n", $db->f($valuefield), $db->f($captionfield)); } else { $return .= sprintf("\n", $db->f($valuefield), $db->f($captionfield)); } } return $return; } /* * Session Management for PHP3 * * Copyright (c) 1998,1999 NetUSE GmbH * Boris Erdmann, Kristian Koehntopp * * $Id: db_pgsql.inc,v 1.13 1999/10/31 20:06:46 kk Exp $ * */ class DB_Sql { var $Host = ""; var $Database = ""; var $User = ""; var $Password = ""; var $Link_ID = 0; var $Query_ID = 0; var $Record = array(); var $Row = 0; var $Errno = 0; var $Error = ""; var $Auto_Free = 0; # Set this to 1 for automatic pg_freeresult on # last record. function ifadd($add, $me) { if("" != $add) return " ".$me.$add; } function connect() { if ( 0 == $this->Link_ID ) { $cstr = "dbname=".$this->Database. #$this->ifadd($this->Host, "host="). #$this->ifadd($this->Port, "port="). $this->ifadd($this->User, "user="). $this->ifadd($this->Password, "password="); $this->Link_ID=pg_pconnect($cstr); if (!$this->Link_ID) { $this->halt("Link-ID == false, pconnect failed"); } } } function query($Query_String) { $this->connect(); # printf("
Debug: query = %s
\n", $Query_String); $this->Query_ID = pg_Exec($this->Link_ID, $Query_String); $this->Row = 0; $this->Error = pg_ErrorMessage($this->Link_ID); $this->Errno = ($this->Error == "")?0:1; if (!$this->Query_ID) { $this->halt("Invalid SQL: ".$Query_String); } return $this->Query_ID; } function next_record() { $this->Record = @pg_fetch_array($this->Query_ID, $this->Row++); $this->Error = pg_ErrorMessage($this->Link_ID); $this->Errno = ($this->Error == "")?0:1; $stat = is_array($this->Record); if (!$stat && $this->Auto_Free) { pg_freeresult($this->Query_ID); $this->Query_ID = 0; } return $stat; } function seek($pos) { $this->Row = $pos; } function lock($table, $mode = "write") { if ($mode == "write") { $result = pg_Exec($this->Link_ID, "lock table $table"); } else { $result = 1; } return $result; } function unlock() { return pg_Exec($this->Link_ID, "commit"); } function metadata($table) { $count = 0; $id = 0; $res = array(); $this->connect(); $id = pg_exec($this->Link_ID, "select * from $table"); if ($id < 0) { $this->Error = pg_ErrorMessage($id); $this->Errno = 1; $this->halt("Metadata query failed."); } $count = pg_NumFields($id); for ($i=0; $i<$count; $i++) { $res[$i]["table"] = $table; $res[$i]["name"] = pg_FieldName ($id, $i); $res[$i]["type"] = pg_FieldType ($id, $i); $res[$i]["len"] = pg_FieldSize ($id, $i); $res[$i]["flags"] = ""; } pg_FreeResult($id); return $res; } function affected_rows() { return pg_cmdtuples($this->Query_ID); } function num_rows() { return pg_numrows($this->Query_ID); } function num_fields() { return pg_numfields($this->Query_ID); } function nf() { return $this->num_rows(); } function np() { print $this->num_rows(); } function f($Name) { return $this->Record[$Name]; } function p($Name) { print $this->Record[$Name]; } ## contributed Saillard Luc function nextid($seq_name) { $this->connect(); $q_id=@pg_exec($this->Link_ID,"select nextval('$seq_name')"); if (!$q_id) { if (!@pg_exec($this->Link_ID,"create sequence $seq_name")) { $this->halt("
nextid() function - unable to create sequence"); return 0; } $q_id=@pg_exec($this->Link_ID,"select nextval('$seq_name')"); if (!$q_id) { $this->halt("
pg_exec() failed:
nextID function"); return 0; } } $r=@pg_fetch_row($q_id, 0); if ($r==false) $nextid=0; else $nextid=$r[0]; return $nextid; } function halt($msg) { printf("Database error: %s
\n", $msg); printf("PostgreSQL Error: %s (%s)
\n", $this->Errno, $this->Error); die("Session halted."); } function table_names() { $this->query("select relname from pg_class where relkind = 'r' and not relname like 'pg_%'"); $i=0; while ($this->next_record()) { $return[$i]["table_name"]= $this->f(0); $return[$i]["tablespace_name"]=$this->Database; $return[$i]["database"]=$this->Database; $i++; } return $return; } } ?>