Location: PHPKode > projects > Aukyla Platform > plugins/DatabaseHandlers/PostgreSQL_DatabaseHandler.php
<?php
/*
     PostgreSQL_DatabaseHandler.php, provides a DatabaseHandler implementation
                                     for PostgreSQL
     Copyright (C) 2005 Arend van Beelen, Auton Rijnsburg

     This program is free software; you can redistribute it and/or modify it
     under the terms of the GNU General Public License as published by the Free
     Software Foundation; either version 2 of the License, or (at your option)
     any later version.

     This program is distributed in the hope that it will be useful, but WITHOUT
     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
     more details.

     You should have received a copy of the GNU General Public License along
     with this program; if not, write to the Free Software Foundation, Inc.,
     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

     For any questions, comments or whatever, you may mail me at: hide@address.com
*/

require_once('DatabaseHandler.php');
require_once('String.php');

class PostgreSQL_DatabaseHandler implements DatabaseHandler
{
	public function connect($server, $database, $username, $password)
	{
		$port = 5432;
		if(strchr($server, ':'))
		{
			$server = String::substringBefore($server, ':');
			$port = String::substringAfter($server, ':');
		}

		if(($this->handle = pg_connect("host=$server port=$port dbname=$database user=$username password=$password")) == false)
		{
			return false;
		}

		$this->server = $server;
		$this->database = $database;
		$this->username = $username;

		return true;
	}

	public function disconnect()
	{
		pg_close($this->handle);
	}

	public function type()
	{
		return 'PostgreSQL';
	}

	public function server()
	{
		return $this->server;
	}

	public function database()
	{
		return $this->database;
	}

	public function username()
	{
		return $this->username;
	}

	public function query($sqlQuery)
	{
		$this->result = pg_query($this->handle, $sqlQuery);

		return ($this->result !== false);
	}

	public function error()
	{
		return pg_last_error($this->handle);
	}

	public function numberOfRows()
	{
		return pg_num_rows($this->result);
	}

	public function numberOfAffectedRows()
	{
		return pg_affected_rows($this->result);
	}

	public function hasResults()
	{
		return ($this->numberOfRows() > 0);
	}

	public function hasAffectedRows()
	{
		return ($this->numberOfAffectedRows() > 0);
	}

	public function result($row, $field)
	{
		$rowArray = pg_fetch_row($this->result, $row);

		return $rowArray[$field];
	}

	public function resultArray()
	{
		return pg_fetch_array($this->result);
	}

	public function resultObject()
	{
		return pg_fetch_object($this->result);
	}

	public function resetResults()
	{
		return pg_result_seek($this->result, 0);
	}

	public function insertId()
	{
		return pg_last_oid($this->result);
	}

	private $database;
	private $handle;
	private $result;
	private $server;
	private $username;

}

?>
Return current item: Aukyla Platform