1

I am using Zend on Quercus/Tomcat and I want to connect to Oracle using Zend_db.

(a) How to make Quercus connect to Tomcat JNDI data source to a Oracle database

(b) How to make Zend_db to connect to that data source

The PDO::getAvailableDrivers() shows the below output

0->mysql

1->pgsql

2->java

I found some steps for (a) but I am not sure how to verify it. 3->jdbc

virimchi
  • 11
  • 2

1 Answers1

0

this is what i do for zend to connect to oracle and it works perfectly

in the Zend Library in the Zend\Db directory i have made a file called Dbname.php

<?php
date_default_timezone_set("Europe/London");
require_once 'Zend/Registry.php';

/**
 * Class for creeating an Oracle SQL Dbname.
 *
 * @Author     Chris Robinson cghrmauritius@gmail.com
 */
class Zend_Db_Dbname
{
 public static function get($arr) {

     $enviroment = Zend_Registry::get("enviroment");

     if(isset($arr[$enviroment.":db"])){

         $retArray = $arr[$enviroment.":db"];

         $dbName = "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)
                        (HOST={$retArray['host']})(PORT={$retArray['port']})))";

         $dbName .= "(CONNECT_DATA=";

         if(isset($retArray['pooled'])){
             if($retArray['pooled'] == 1)
                $dbName .= "(SERVER = POOLED)";
         }
         if(isset($retArray['sid'])){
            $dbName .= "(SID={$retArray['sid']})))";
         }else if(isset($retArray['serviceName'])){
            $dbName .= "(SERVICE_NAME={$retArray['serviceName']})))";
         }

         $retArray['dbname'] = $dbName;

         unset($retArray['pooled']);

         return $retArray;
     }
     return "Missing '".$this->enviroment.":db' from application.ini";       
 }
}


?>

also i have an ini file ('myfilename.ini') which holds all the db connection details for our dev and production dbs which is as follows

[global]

salt    = "qZPJeZbQv])7fnKxS’U0\2V^Eg.|})+obZ:H6|y.[#EBqo;Evp"
api     = "d5f75f4ddc0a5cead40b4269ca28b217b71ed893";

[production]

debug = false

[production:db]

host    = xx.xx.xx.xxx
username    = myusername
password    = mypassword
port    = xxxx
charset     = "WE8ISO8859P1"
pooled  = true
sid     = mysid

[development]

debug = true

[development:db]

host        = xx.xx.xx.xxx
username    = myusername
password    = mypassword
port        = xxxx
charset     = "WE8ISO8859P1"
pooled      = false
sid         = mysid
debug       = true

then in my website code or class which is to make the connection

Zend_Registry::set("enviroment", "production");
$arr = parse_ini_file('myfilename.ini',true);
$options = Zend_Db_Dbname::get($arr);
$db = Zend_Db::factory('Oracle', $options);

Using this method i find extremely useful and quick to create new classes / pages / apis ect and allows to very quickly switch between development and production servers.

If you need any further help just ask away.

cghrmauritius
  • 177
  • 1
  • 3
  • 15