<?php
require_once 'Zend/Db.php';
/**
* It makes the connection to the database, using the Zend_DB - Zend Framework.
*
* @author Fabio Xavier de Lima
* @version 1.0 - Creation Date: 23/06/2008 - Last Modfied: 01/07/2008
*/
class ConnectDB{
private $database;
private $parameters;
private $db;
/**
* Builder of the class.
*
* @param string $adapterName - database name
* @return class ConnectDB
*/
function ConnectDB($adapterName){
$this->database = $adapterName;
}
/**
* Create connection with database.
*
* @return Return the connection to the database,
* of accord with adapterName informed.
*/
function getConnection(){
switch (strtolower($this->database)){
case null:
$this->db = 'Informing the corresponding AdpaterName.';
break;
case 'oracle':
$oracle = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=xx.100.100.x)(Port=1521))(CONNECT_DATA=(SID=ora10g)))';
$this->parameters = array('host'=>'xx.100.100.x','username'=>'test','password'=>'test','dbname'=>$oracle);
$this->db = Zend_Db::factory('Oracle', $this->parameters);
break;
default:
$this->db = 'Implement other databases';
break;
}
return $this->db;
}
/**
* Destroying the connection.
*/
function __destruct() {
if (isset($this->db)) {
$this->db->closeConnection();
}
}
}
?>