|
|
|
<?php
if($dbObjDefined != 1)
{
$dbObjDefined = 1;
//Wrapper class for database calls
class dbObj
{
//Connection handle to database
var $conn;
//Default connection parameters
var $host = "YourSite.com";
var $user = "johndoe";
var $password = "pwd";
var $port = "5432";
var $dbname = "MyDB";
//Open initial connection. $params is an associative array holding
//parameters to the pg_Connect function.
function init($params)
{
if(isset($parame[host]))
$host = $parame[host];
else
$host = $this->host;
if(isset($parame[user]))
$user = $parame[user];
else
$user = $this->user;
if(isset($parame[password]))
$password = $parame[password];
else
$password = $this->password;
if(isset($parame[port]))
$port = $parame[port];
else
$port = $this->port;
if(isset($parame[dbname]))
$dbname = $parame[dbname];
else
$dbname = $this->dbname;
$this->conn = pg_Connect ( " host=$host user=$user password=$password port=$port dbname=$dbname
");
}
//Send SQL to database connection.
//Return recordset object on success.
//Return 0 on failure.
function exec($SQL)
{
$resultset = pg_Exec($this->conn, $SQL);
if ($resultset) {
$recset = new recordset;
$recset->init($resultset);
return $recset;
}
else {
return 0;
}
}
//Close connection to database
function free()
{
pg_close($this->conn);
}
};
/*
This is a simple recordset class which can be
traversed using next(), prev(), and current() methods.
It is initialized from a resultset returned from the
function "pg_Exec" or can be generated by a call to the
exec method from the dbObj.
*/
class recordset
{
var $resultset;
var $index;
var $numFields;
var $numTuples;
function init($newResultset)
{
$this->resultset = $newResultset;
$this->index = 0;
$this->numFields = pg_NumFields($this->resultset);
$this->numTuples = pg_NumRows($this->resultset);
}
//Get a value by row name and either column name or column number
function getVal($row, $col)
{
return pg_Result($this->resultset, $row, $col);
}
//Return an array of field names
function getFields()
{
for($i=0; $i<$this->numFields; $i++)
$retArray[] = pg_FieldName($this->resultset, $i);
return $retArray;
}
//Get number of columns in resultset
function getNumFields()
{
return $this->numFields;
}
//Get a tuple (associative array of column values) by row number
function getTupleDirect($row)
{
for($i=0; $i<$this->numFields; $i++)
$retArray[pg_FieldName($this->resultset, $i)] =
pg_Result($this->resultset, $row, $i);
return $retArray;
}
//Get tuple pointed to by the current index
function getTuple()
{
if($this->index>=0 && $this->index < $this->numTuples)
return $this->getTupleDirect($this->index);
else
return 0;
}
//Get an array filled with all values in a column
//(using either column name or column number)
function getColumn($col)
{
for($i=0; $i<$this->numTuples; $i++)
$retArray[] = pg_Result($this->resultset, $i, $col);
return $retArray;
}
//Return the number of records in the recordset
function getNumTuples()
{
return $this->numTuples;
}
//Return 1 if index is within bounds of the recordset
function current()
{
if($this->index>=0 && $this->index < $this->numTuples)
return 1;
else
return 0;
}
//Incriment index
function next()
{
if($this->index<$this->numTuples)
{
$this->index++;
return 1;
}
else
{
return 0;
}
}
//Decriment index
function prev()
{
if($this->index >= 0)
{
$this->index--;
return 1;
}
else
{
return 0;
}
}
//Reset index to 0
function reset()
{
$this->index = 0;
}
//Free memory allocated to recordset.
function free()
{
pg_Freeresult($this->resultset);
}
};
}
?>
|
|
| PostGreSQL and MySQL 2 in 1 db Manager Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL | | | Script for postgresql to walk through the results limiting the results shown per
page. Categories : PostgreSQL, Databases, PHP | | | Monthly and Daily Upcoming Events calendar. Categories : Date Time, PostgreSQL, PHP, Calendar, Databases | | | This is just a tiny example showing how to create a PostgreSQL large object from PHP3 Categories : Databases, PostgreSQL, PHP | | | AUTH (.htaccess style) - a login system that uses PostgreSQL. Categories : PHP, Authentication, Databases, PostgreSQL | | | DBE - Database Expander: Edit PostgreSQL individual database tables online via your Web browser! Categories : PostgreSQL, Complete Programs, Databases, PHP Classes, PHP | | | Logs hits to any page which includes it. Automatically utilises page access information left behind by PHP/FI2.0. Categories : Databases, PHP, mSQL, Databases | | | Save and restore files into postgresql database (PHP SCRIPT) PHP CLASS Categories : PHP, Databases, PostgreSQL, Filesystem | | | Is there any way to test that the $result has null values or not without reading the field values in the results in postgre?
Categories : PostgreSQL, PHP, Databases | | | Postgresql Database Backup And Restore PHP script Categories : PHP, Databases, PostgreSQL | | | This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases, MySQL, Complete Programs, PHP, Databases | | | This is a function to display a table for Postgres results. This this code in an include file, require it, and call ShowResults($result) whenever you need to see what your queries result in. Categories : Databases, PHP, PostgreSQL | | | This is Yet Another Sql Abstraction Library. Include it in your script and you can use the most important SQL functions without worrying about the SQL backend. Categories : Databases, PHP, ODBC, MySQL, PostgreSQL | | | Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs. Categories : Databases, PHP, MySQL, Complete Programs | | | phpAds, a complete banner and ad management system with detailled tracking and stats. Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases | |
|
|
|