note 43737 modified in function.ocilogon by sixd
| From: | sixd@php.net | Date: | Mon, 05 Oct 2009 01:39:43 +0000 |
| Subject: | note 43737 modified in function.ocilogon by sixd | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161298@lists.php.net to get a copy of this message | ||
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 // test-oracle.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;
}
#putenv("ORACLE_SID=ORTD");
#putenv("ORACLE_HOME=/u01/app/oracle/product/9.2.0.1.0");
$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);
?>
--was--
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 // test-oracle.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;
}
#putenv("ORACLE_SID=ORTD");
#putenv("ORACLE_HOME=/u01/app/oracle/product/9.2.0.1.0");
$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);
?>
http://php.net/manual/en/function.ocilogon.php