ESCAPING FROM OCI() ERRORS
I assume that you have already a PHP file for use to connect Oracle. Create or Copy any one of them into "DocumentRoot" ("/usr/local/apache/htdocs" in here) and try to run it in your browser.
I hope you did not get an error like
Warning: ocilogon(): _oci_open_server: Error while trying to retrieve text for error ORA-12545 in ....
This error is telling you did not specify "ORACLE_SID" in your script or
Warning: ocilogon(): _oci_open_server: Error while trying to retrieve text for error ORA-12154 in ...
This error could not find any match "ORACLE_SID" you specified in "TNSNAMES.ORA" file.
If you got one of these error, your environment variables must introduce to your apache web server.
Remember that you compiled apache with Oracle user and group. So, do the following:
create a file named "oraenv" in "/usr/local/apache/conf/" directory and put the following lines in it:
(IMPORTANT : Please change <ORAHOME> with $ORACLE_HOME and <ORASID> with $ORACLE_SID environment variables of your Oracle user..)
Here is an example for this "oraenv" file:
LD_LIBRARY_PATH=/opt/oracle/product/8.1.7/lib:/usr/local/apache/lib:/usr/local/lib
ORACLE_HOME=/opt/oracle/product/8.1.7
ORACLE_SID=/opt/oracle/product/8.1.7
TNS_ADMIN=/opt/oracle/product/8.1.7/network/admin
NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1 #for English
#NLS_LANG=TURKISH_TURKEY.WE8ISO8859P9 #for Turkish
ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
If you want You may insert these lines into "/usr/local/apache/bin/apachectl" file directly.
Now You need to edit "/usr/local/apache/bin/apachectl" file. Open it by a text editor and add the following lines to anywhere in the "CONFIGURATION SECTION"
if [ -f /usr/local/apache/conf/oraenv ] ;
then
. /usr/local/apache/conf/oraenv
fi
IMPORTANT NOTES :
Make sure Oracle Listener and Oracle Database have already started while Apache Server starting/restarting.
"oraenv" file will be included in all attempting to start or restart apache web server. Don't delete this file anyway.)
In all of your php scripts, you need to add "ORACLE_SID" at connection line like (Replace "orcl" with your ORACLE_SID.) I recommend you to use a connection function as follows and require it in your scripts:
<?
class oraClass
{
var $sql, $stmt, $conn, $nrows, $ncols, $errmsg, $user, $pass;
function db_connect()
{
if($this->conn = OCILogon($this->user, $this->pass, $_ENV['ORACLE_SID']))
$this->db_parse();
else
$this->get_error($this->conn);
}
.
.
.
?>
Now you can use your great database with your great web development language.
If you have any question or suggestions drop an email to my mailbox.
I hope this tutorial will help you too...
Partager