Login   Register  
PHP Classes
elePHPant
Icontem

File: class.interbase.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Vinicius Gallafrio  >  Interbase  >  class.interbase.php  >  Download  
File: class.interbase.php
Role: ???
Content type: text/plain
Description: class
Class: Interbase
Author: By
Last change:
Date: 2002-01-24 11:16
Size: 3,744 bytes
 

Contents

Class file image Download
<?
//------------------------------------------------ 
class interbase {
//------------------------------------------------
/**
 * Autor: Vinicius Gallafrio/BR - vinicius@72k.net
 * Date : 24/01/2002
 * http://www.72k.net
 * 
 * Description: PHP Class for Interbase Connection
 * 
 * EXAMPLES:
 * 
 * SELECT
 * include "class.interbase.php";
 * $ibase = New interbase('/path/to/database.gdb','sysdba','masterkey',0);
 * $ibase->query("SELECT field FROM table");                           ^-- change to 1 for debug mode
 * 
 * while ($ibase->movenext()) { 
 * 		echo $ibase->getfield("field");
 * }
 * 
 *   
 * INSERT
 * include "class.interbase.php";
 * $ibase = New interbase('/path/to/database.gdb','sysdba','masterkey',0);
 * $ibase->query("INSERT INTO table (field) values ('value')");
 * 
 * UPDATE
 * include "class.interbase.php";
 * $ibase = New interbase('/path/to/database.gdb','sysdba','masterkey',0);
 * $ibase->query("UPDATE table SET field='newvalue' WHERE fieldID=1");
 * 
 * DELETE
 * include "class.interbase.php";
 * $ibase = New interbase('/path/to/database.gdb','sysdba','masterkey',0);
 * $ibase->query("DELETE FROM table WHERE fieldID=1");
 * 
 * 
 */
 
	/* public: connection parameters */
	var $debug;
	var $database;
	var $user;
	var $password;
	
	/* private: connection parameters */
	var $conn;
	var $rstemp;
	var $record;
	
	
	/**
	 * interbase::interbase()
	 * Constructor this class - define public connection parameters and
	 * call the connect method
	 * 
 	 * @param $database
	 * @param $user
	 * @param $password
	 * @param $debug
	 */
	function interbase ($database,$user,$password,$debug=0) {

		$this->debug = $debug;
		if ($this->debug) echo "\n\nDebug On <br>\n";		
		
    	$this->user = $user;
	    $this->password = $password;
	    $this->database = $database;
		
		/**
         * open connection
         */
		$this->connect();
	}
	    
	
    /**
     * interbase::connect()
     * Open connection with the server
	 * 
     * @return id da conexao
     */
    function connect () { 
		    
         /**
          * Open connection
          */
         if ($this->debug) echo "Connecting  to $this->database <br>\n";
         $this->conn = @ibase_pconnect($this->database,$this->user,$this->password)
              			or die("Error:" . ibase_errmsg() . "<br>\n");	
            	
         return $this->conn;				
    }
	
	/**
	 * interbase::query()
	 * Execute SQL
	 * 
	 * @param $sql
	 * @return 
	 */
	function query($sql) {
		
		if ($this->debug) echo "Execute SQL:  $sql <br>\n\n";
		$this->rstemp = @ibase_query($this->conn,$sql) 
		            or die("Error:" . ibase_errmsg() . "<br>\n"); 					

		return $this->rstemp;
	
	}
		
  	/**
  	 * interbase::movenext()
	 * fetch next record in result
  	 * 
  	 * @return 
  	 */
  	function movenext(){
		
		if ($this->debug) echo "Fetching next record  ... ";
	    $this->record = @ibase_fetch_object($this->rstemp);
		
		if ($this->debug && $this->record) echo "OK <br>\n\n";
		elseif ($this->debug) echo "EOF <br>\n\n";
		
	    return $this->record;
	}
  
  
	/**
	 * interbase::getfield()
	 * get field value from the current record
	 * 
	 * @param $field
	 * @return 
	 */
	function getfield($field){
	
		if ($this->debug) echo "Getting $field  <br>\n\n";
		
   		/**
 	     * first we will look to the field writing in UPPER
  	     */
		$field = strtoupper($field);
		if ($this->record->$field) {
			return $this->record->$field;
		} else { 
		/**
		 * look to the field writing in lower
		 */	
			$field = strtolower($field);
			return $this->record->$field;
		}
	}	
  	
}

?>