Data Driven Design icon

Connecting Zend Framework 2 to an Oracle Backend

ZF2's documentation on connecting to an Oracle database is sparse at best. Here are a couple of examples of how to setup the connection. This is a basic connection. Note the character_set key. If this isn't set the Oracle driver will improperly encode special characters when sending and receiving data.

return array(
  'db' => array(
    'driver' => 'Oci8',
    'connection' => 'orcl', // Name of conenction in tnsnames.ora
    'username' => 'username', // Username to access db
    'password' => 'password', // Password to access db
     
    /*
     * Explictly set the character set here or the oracle driver will create null characters where
     * special characters are used.
     */
    'character_set' => 'AL32UTF8',
  )
);

Here is an example of setting up multiple Oracle connections.

return array(
  'adapters' => array(
    'db' => array(
      'connection1' => array(
        'driver' => 'Oci8',
        'connection' => 'orcl',
        'username' => 'username',
        'password' => 'password',
        'character_set' => 'AL32UTF8',
      ),
      'connection2' => array(
        'driver' => 'Oci8',
        'connection' => 'orcl',
        'username' => 'username',
        'password' => 'password',
        'character_set' => 'AL32UTF8',
    )
  )
);
Get In Touch.
Contact