Zend php connect to oracle using tnsnames

This few days I am trying to configure my Linux server Zend PHP to connect oracle by using the tnsnames.ora profile.

For my finding, there are several ways to do so.

1. Install the oracle clients into the Linux server & it will set the environment variable TNS_ADMIN to the correct path for the tnsnames.ora. But I not taking this approach due to the Linux server is not under our control.

2. Create a shell script & enable the shell script to execute once the server starting & export the TNS_ADMIN variable to path “/usr/local/Zend/Core/network/admin/” directory (the path is where the tnsnames.ora located, you may also change the path to any directory where your tnsnames.ora located)

3. In your php script, add in a command to set the environment varialbe TNS_ADMIN to “/usr/local/Zend/Core/network/admin/” by using php command. 
Add in this command before establish connection to oracle. 

I am using third solution due to I got not control on the Linux server, I only able to access on the application layer.  Below is some coding example.

//Previous connection method
function connect(){
     $database = ociplogon(“username”, “password”,”//”);
     return $databases;

//Enhanced method using tnsnames profile
function connect(){
     $database = ociplogon(“username”, “password”,”ora_profile_name_in_tnsnames”);
     return $databases;

One Comment to “Zend php connect to oracle using tnsnames”

  1. T 5 February 2009 at 10:49 pm #

    You have typos as your return variables. Surely you want to return $database in both cases 🙂

Leave a Reply