Oracle ZF-2 Integration

Oracle  Integration

——————————————————————————————————————————————————

Following are the Oracle simple connection

We use tnsnames.ora to connect

<?php
$tns = “
(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS =
                (PROTOCOL = TCP)
                (Host = istctdb02-vip)
                (Port = 1521))
    )
    (CONNECT_DATA =
      (SID = SidName)  // SID name will available when you connect Db using SQL developer.
    )
  )
       “;
$db_username = “username”;
$db_password = “password”;
try{
    $conn = oci_connect($db_username, $db_password, $tns);
    if (!$conn) {
        $e = oci_error();
        trigger_error(htmlentities($e[‘message’], ENT_QUOTES), E_USER_ERROR);
    }
    print_r($conn);
}catch(\Exception $e){
    echo ($e->getMessage());
}

——————————————————————————————————————————————————

Oracle  ZF-2 Integration

——————————————————————————————————————————————————

Step1: Update local.php

 

‘oracle’ => array(
‘tns’ => ‘(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = TCP)
(Host = hostname)
(Port = 1521))
)
(CONNECT_DATA =
(SID = SidName)))’,
‘username’ => ‘username’,
‘password’ => ‘password’
)

Step2: update model.php which manage Databases.

 

public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
$this->table = ”;
$this->resultSetPrototype = new ResultSet(ResultSet::TYPE_ARRAY);
$this->initialize();
$this->oracleConnection();
}

private function oracleConnection()
{
$db = require (__DIR__ . ‘/../../config/autoload/local.php’);
if (isset($db[‘oracle’]) && ! empty($db[‘oracle’])) {
$db = $db[‘oracle’];
try {
$conn = oci_connect($db[‘username’], $db[‘password’], $db[‘tns’]);
if (! $conn) {
$error = oci_error();
throw new \Exception($error[‘message’]);
} else {
$this->oracle_connection = $conn;
}
} catch (\Exception $exec) {
echo $exec->getMessage();
}
}
}

 

 

it will work successfully.

🙂

Add a Comment

Your email address will not be published. Required fields are marked *