If you get your connectivity working with putenv on ORACLE_SID and ORACLE_HOME, but you do not want to use putenv because you want safemode on. You will need to pass these from your environment variables. Somehow setenv in httpd.conf did not do the trick for me... the values are set but the connectivity does not work. Then you will need to set the environment in your /etc/init.d/apachectl or /etc/profile and use a "PassEnv ORACLE_HOME ORACLE_SID" directive in httpd.conf so that these variables are picked up by php.
However, when you suexec in Apache 2.0, the server will only allow you to pass a given set of variables which are defined in the apache source code in the file apache-dir/support/suexec.c
In order to pass ORACLE_SID and ORACLE_HOME to PHP you need to add these to that file. The relevant changed piece of code where I added "ORACLE_" looks something like this:
char *safe_env_lst[] =
{
/* variable name starts with */
"HTTP_",
"SSL_",
"ORACLE_",
/* variable name is */
...
You will have to do a "make clean", "./configure", "make", "make install". Do not forget to do the "make clean" or the apache changes will not be picked up.
Here is a nice php test script :)
<?php function dump_array($a_value)
{
reset($a_value);
for ( $s_str = '' ; list($s_key, $x_value) = each($a_value) ; )
{
$s_str .= " ".
"<span style=\"color:green\">[</span>$s_key<span style=\"color:green\">]</span> = ".
"<span style=\"color:red\">[</span>$x_value<span style=\"color:red\">]</span><br />";
}
reset($a_value);
echo $s_str;
}
$ORACLE_SID = getenv("ORACLE_SID");
$ORACLE_HOME = getenv("ORACLE_HOME");
echo "ORACLE_SID = $ORACLE_SID<br>";
echo "ORACLE_HOME = $ORACLE_HOME<br>";
$cn = ociplogon('scott', 'tiger');
echo "cn = $cn<br />\n";
$st = ociparse($cn, "select tname from tab");
echo "st = $st<br />\n";
$ex = ociexecute($st,OCI_COMMIT_ON_SUCCESS);
echo "ex = $ex<br />\n";
$mr = ocifetchinto($st,$xx,OCI_ASSOC);
while ( $mr )
{
dump_array($xx);
$mr = ocifetchinto($st,$xx,OCI_ASSOC);
}
$fr = ocifreestatement($st);
echo "fr = $fr<br />";
ocicommit($cn);
ocilogoff($cn);
?>