473,379 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

PHP 5.0.0 and the OCI8 module

I am relatively new to PHP, but with over a decade of experience in C
and other programming languages I can usually pick up a new
programming language relatively quickly (to be reasonably productive
not to know it inside out). My issues I believe may be either solely
concentrated on the platform I am running PHP 5.0.0 on (MS Windows
2000) or just the Oracle OCI8 module (running against an Oracle
8.1.7.4 installation). In either case I am using PHP in more of a
pure scripting environment with no Web-related access as of yet.

The following (with a modifications only for username and password) is
the script I just started developing:

<?php
$os_name = strtolower(PHP_OS);
if (substr($os_name,0,3) == 'win') {
$dirsep = '\\';
$oci8lib = 'php_oci8.dll';
$pathsep = ';';
$libpath = 'PATH';
} else {
$dirsep = '/';
$oci8lib = 'oci8.so';
$pathsep = ':';
$libpath = 'LD_LIBRARY_PATH';
}
$ORACLE_HOME = getenv('ORACLE_HOME');
if (strlen($ORACLE_HOME) == 0) {
printf("The ORACLE_HOME environment variable has not been set\n");
exit(1);
}
if (!extension_loaded('oci8')) {
$path = split($pathsep,getenv($libpath));
$found = false;
foreach ($path as $dir) {
if (substr($dir,0,strlen($ORACLE_HOME)) == $ORACLE_HOME) {
$found = true;
break;
}
}
if (!$found) {
printf("The OCI8 PHP module has not been autoloaded and
ORACLE_HOME\n");
printf("is not currently found in %-15s; therefore,
the\n",$libpath);
printf("OCI8 PHP module cannot be loaded at runtime.\n");
exit(1);
}
dl($oci8lib);
}
$DBA_HOME = getenv('DBA_HOME');
if (strlen($DBA_HOME) == 0) {
printf("The DBA_HOME environment variable has not been set\n");
exit(1);
}
$dfn = "${DBA_HOME}${dirsep}adm${dirsep}databases.db" ;
if ((!file_exists($dfn)) || (!is_readable($dfn))) {
printf("The DBA databases file:\n");
printf(" ${dfn}\n");
printf("is not available\n");
exit(1);
}
$dfh = fopen($dfn,'r');
if (!$dfh) {
printf("The DBA databases database:\n");
printf(" ${dfn}\n");
printf("is not available\n");
exit(1);
}
$dfd = fgets($dfh);
while (!feof($dfh)) {
$dfd = rtrim($dfd);
if ((strlen($dfd) > 0) && (substr($dfd,0,1) != '#')) {
$dfa = split(':',$dfd);
$user = 'system';
$pass = 'manager';
$host = $dfa[0];
$port = $dfa[1];
$sid = $dfa[2];
$cnxn = oci_connect($user,$pass,"(DESCRIPTION=(ADDRESS_LIS T=(ADDRESS=(HOST=${host})(PORT=${port})(PROTOCOL=T CP)))(CONNECT_DATA=(SID=${sid})))");
$stmt = oci_parse($cnxn,'SELECT USER FROM dual');
oci_execute($stmt);
while ($data = oci_fetch_array($stmt,OCI_ASSOC)) {
foreach ($data as $key => $value) {
printf("${host} ${sid} ${key} = ${value}\n");
}
}
oci_free_statement($stmt);
oci_close($cnxn);
}
$dfd = fgets($dfh);
}
fclose($dfh);
?>

The script is run on the command line as:
php oracle1.php

The file referenced in the script is in the following format:
host:port:sid:level1:level2:notify
where host is the machine name, port the Oracle TNS listener port, sid
is the ORACLE_SID, level1 and level2 (not currently used in the
script) are percentages, and notify is an email address.

My two issues are as follows:
1. Although not the final purpose of the script, an interesting
phenomena occurs in which using "SELECT USER FROM dual" causes the
script to hang after the fclose. I know this because I have done the
simple debugging of printing messages at various points. If I change
the oci_connect to either oci_pconnect or oci_new_connect the script
completes successfully. Similarly, if the query is changed to
something other than including only the USER function (i.e. - "SELECT
USER, dummy FROM dual", "SELECT dummy FROM dual", "SELECT global_name
FROM global_name", etc.), whether oci_connect or either of the other 2
connection methods is utilized, the script also runs to completion.
My question is: what precisely is the "hanging" factor with regards to
using the simple "SELECT USER FROM dual" and oci_connect?

2. In attempting to deduce what had been going on in my script, I
found that regardless of which of the 3 connection methods I used
oci_close always returns a 0 (presumably indicating a FALSE result)
and oci_free_statement returns the expected result of 1 (TRUE). In
essence does oci_close either actually do anything or is it setup to
always return a FALSE? I realize that multiple database connections
in one script may not be the norm and that, as the oci_close
documentation indicates, that it normally is not necessary (as all
connections will be closed on script completion), but if said function
exists or it is expressly stated that multiple database connections
are not supported an oci_close should close the database connection.
I have no issues connecting and any other tool I use, commercial or
not, successfully closes the connection from my machine so it is
bizarre to me as well to always get the FALSE result.

I apologize in advance if this is more a newbie issue than actual
issues, but it is quite perplexing to me as a DBA and programmer as no
other programming environment I've worked on has had an issue as
described above.

Thank you.
Jul 17 '05 #1
0 2088

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
0
by: lok | last post by:
hi all, i have installed oracle9i client tools on RedHat7.3 (x86 machine) and i compiled php4.1.2 & apache1.3 successfully but when i execute php script in browser, error occured: "Fatal error:...
1
by: watayoune | last post by:
Hi, My apache (on win) crash when i start it, after i had oci8 extensions in php.ini ! 1. i had extension phph_oci8.dll in php.ini 2. i've got a php_oci8.dll in my php extensions dir 3. my...
8
by: YeCkeL | last post by:
Warning: oci_new_connect() : OCIEnvNlsCreate() failed. There is something wrong with your system - please check that ORACLE_HOME is set and points to the right directory in...
6
by: DravenStone | last post by:
Hi, I had just a horrible day at work, spent pretty much the entire day trying to get php_oci.dll and php_oracle.dll to load. It still never did. Super Quick Background. Jack of all trades IT...
5
by: Mladen Gogala | last post by:
The latest version of OCI8 1.2.1 doesn't work with LOB fields. There was an open bug, but Tony2001 was his usual helpful self, so he removed the bug and flatly denied its existence. I had to...
5
by: danish | last post by:
I download the oci-1.2.2.tgz file and generated the oci8.so file. After adding the extension=oci8.so in php.ini I get the error unable to load dynamic library /usr/lib/php4/oci8.so
0
by: Yannick | last post by:
Hi, I'm Julien from France, We have recently install a new Web Server for my company The server is composed : - Linux RedHat RHEL4 U4 - Httpd-2.0.52-27.ent - Oracle Database 10.2.0.1
7
by: eholz1 | last post by:
Hello All, I have reviewed various posts in regard to Oracle and PHP. I am running Apache 2.0.59, on Windows XP, with PHP 5.2. I would like to connect using PHP to a remote oracle db (ver. 7)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.