Using PHP’s putenv() function to set environment variables and connecting to an Oracle database

Yay, my first real technical blog post!

I’ve been trying to tackle this issue for a while. I’ve been making a connection to an Oracle database using PHP, but I’d have to modify the environment variables to tell PHP where to find the Oracle installation and the tnsnames.ora file. To do this, I would use the putenv() PHP function to set the ORACLE_HOME and TNS_ADMIN variables. The problem was that it was being really really erratic. It would make a connection one day and the next day it’s not working. Did the freaking server admin make changes to the server? Am I pointing the environment variables to the right place? Trust me, I went over this issue for a long time.

Well the issue is that you’re not even supposed to be usnig putenv() to set environment variables. In fact it’s going to be deprecated by PHP ver. 6.0… Thanks to this PDF on page 100 it states that you’re supposed to be setting the environment variables in the shell that starts Apache. I’ve sent the request in to my server admin (since i don’t have rights) and I’m pretty confident that this will work.


Setting the environment variables on Apache worked…  for the most part.  It still craps out maybe like 10% of the time.  This is still an issue which still needs some investigation.