#-------------------------------# # Retrieve records from a table # # based on SQL passed in # # Postgresql Version # #-------------------------------# function lib_getsql($query, $dbase="") { global $sql, $errormsg, $DBLIB; $sql = $query; $retval = array(); $db = iif($dbase,$dbase,$DBLIB[PGdatabase]); // Check if a transaction was sitting in here if(preg_match('/BEGIN/i', $sql)) $DBLIB[transaction] = 1; // If we were finished, then reset the transaction flag if(preg_match('/COMMIT/i', $sql)) $DBLIB[transaction] = 0; $cstring = "host=".$DBLIB[PGhost]." port=".$DBLIB[PGport]." dbname=".$db." user=".$DBLIB[PGuser]." password=".$DBLIB[PGpassword]; if($DBLIB[PGpersistent]) $db = @pg_connect($cstring); else $db = @pg_connect($cstring); $result = @pg_exec($sql); if($result) { $num = @pg_numrows($result); for($i=0; $i<$num; $i++) $retval[] = @pg_fetch_array($result,$i,PGSQL_ASSOC); } else { $errormsg = pg_errormessage($db); // Was there a transaction before? if($DBLIB[transaction] == 1) { @pg_exec("ROLLBACK TRANSACTION"); } if($_SESSION[user][role] == "admin") { #$errormsg = pg_errormessage($db); $out = "

ERROR

"; $out .= "
Postgres Database ERROR:
$errormsg

SQL Statement: $sql


"; lib_main($out); } else { $errormsg = "

ERROR:

"; $out = "An error DB101 was received from client $REMOTE_ADDR
"; $out .= "Please contact the administrators of this site at development@did-it.com
"; $out .= "and place the above error message in the body of your message."; } exit; } return $retval; }#fi get_records #-------------------------------# # Insert records in a table # #-------------------------------# function lib_insert($table="", $arr="", $dbase="") { global $sql, $errormsg; if(!is_array($arr)) return(0); while(list($k, $v) = each($arr)) { $cols[] = $k; $vals[] = $v; }#-wend if($DBLIB[engine] == "pgsql") $names = '"'.join('","',$cols).'"'; else $names = join(',',$cols); $vals = "'" . join("','",$vals) . "'"; $retval = 0; $sql = "INSERT INTO $table ($names) VALUES($vals)"; lib_getsql($sql, $dbase); #print "\n"; return($retval); }#-end lib_insert #-------------------------------# # Do a simple db update # #-------------------------------# function lib_update($table="", $key_col="", $key_val="", $arr="", $dbase="" ) { global $sql, $errormsg; if(!$table || !$key_col || !$key_val || !$arr) { return(0); }#fi while(list($k, $v) = each($arr)) $pairs[] = "$k='$v'"; $cols = join(",", $pairs); $retval=0; $sql = "UPDATE $table SET $cols WHERE $key_col ='$key_val'"; lib_getsql($sql, $dbase); return(0); }#end lib_update