Login   Register  
PHP Classes
elePHPant
Icontem

File: lib_dbi.class

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Thomas Werner  >  DBI  >  lib_dbi.class  >  Download  
File: lib_dbi.class
Role: ???
Content type: text/plain
Description: Datebase Interface
Class: DBI
Author: By
Last change:
Date: 2001-01-28 14:30
Size: 2,079 bytes
 

Contents

Class file image Download
<?php
 
Class DBI extends CONFIG
{
	/*******************************************************************************
	
	Description   	: 	PHP Database Interface
	Author        	: 	Thomas Werner
	Author Email  	: 	thomas.werner@ideaweb.de
	Created       	: 	20000801
	Last Modified 	: 	20001201
	
	Info			: 	n/a
	
	*******************************************************************************/
	
	var $DBD;
	var $CONN;
	
	var $prepare = "";
	var $row     = array();

	function error($str)
	{
		echo "$str<BR>\n";
		exit;
		
	} // End Error

	function DBI()
	{
		$dbtype  = $this->dbtype;
		if(!$GLOBALS['lib_dbd_'.$dbtype."_read"]) {
			include('lib_dbd_'.$dbtype.'.class');
		}
		$DBDClass = 'DBD_'.$dbtype;
		$this->DBD = new $DBDClass;
		
		//$this->pconnect();
	}

	function connect()
	{
		$dbtype  = $this->dbtype;
		$dbhost  = $this->dbhost;
		$port    = $this->port;
		$dbname  = $this->dbname;
		$dbuser  = $this->dbuser;
		$dbpwd   = $this->dbpwd;
		
		$this->CONN = $this->DBD->connect($dbname,$dbhost.":".$port,$dbuser,$dbpwd);
		
		return true;
		
	} // End Connect
	
	function pconnect()
	{
		$dbtype  = $this->dbtype;
		$dbhost  = $this->dbhost;
		$port    = $this->port;
		$dbname  = $this->dbname;
		$dbuser  = $this->dbuser;
		$dbpwd   = $this->dbpwd;
		
		$this->CONN = $this->DBD->pconnect($dbname,$dbhost.":".$port,$dbuser,$dbpwd);
		
		return true;
		
	} // End Connect

	function disconnect()
	{
		if($this->DBD){
		$this->DBD->disconnect();
		}
	} // End Disconnect
	
	function prepare($query)
	{    
		if(!$this->CONN){return;}
		$sth = $this->DBD->prepare($query);
    	return($sth);
  
	} // End Prepare

	function value($table, $id, $name)
	{
		if ( $this->CONN) {
			$dbexec = $this->DBD->prepare("SELECT * FROM $table WHERE ID = $id");
			if ( $dbexec->execute() && $dbexec->rows() > 0 ) {
				$row = $dbexec->fetchrow_hashref();	
				return $row->{$name};
			}
		}
		return false;
	} // End value
	
}	// End Class

$GLOBALS[lib_dbi_read] = 1;

?>