Skip to Main Content

DevOps, CI/CD and Automation


For appeals, questions and feedback, please email

oci_connect() fails sometimes

854760Apr 12 2011 — edited Oct 30 2012

I am familiar with php and mysql, but just beginning to use oracle. I have a very simple script which seems to sometimes work and sometimes not, and I can't really figure out the reason.

The php script simply reads some values from a table (see below). Sometimes it works as it should. But when I reload it a few times the following error appears:

Warning: oci_connect() [function.oci-connect]: OCIEnvNlsCreate() failed. There is something wrong with your system - please check that LD_LIBRARY_PATH includes the directory with Oracle Instant Client libraries in ...

And sometimes I get the following error:

Warning: oci_connect() [function.oci-connect]: ORA-00604: error occurred at recursive SQL level 1 ORA-12705: Cannot access NLS data files or invalid environment specified in ...

Sometimes, after a few more reloads, the script works again. I don't see any pattern.

The errors seem to indicate that something on the server side is messed up. But on the other hand, the script works from time to time. So my basic questions is: are such error produced by my php script, or are they php bugs, is it an apache problem or maybe some problem with the oracle installation? (I'm using the db of a large institution, that's why I doubt that the reason is a mis-configuration, but who knows). Maybe I should say that I also use sqldeveloper and without problems so far, so the connection seems to work. I also made sure I use the correct service string as specified in the tnsnames.ora.

Here is the php script, I guess it's pretty standard:

ini_set ("display_errors", "1");
$c = oci_connect('...', '...', '...');
if(!$c) { /* some error handling */ }
$s = oci_parse($c, 'select TS from TEST_LOG');
while ($res = oci_fetch_array($s, OCI_ASSOC)) { echo $res['TS']; }

I'm using php 5.2.11 on SunOS 5.10 and oracle 10.2g.

Any hints pointing me in the right direction are welcome!
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 27 2012
Added on Apr 12 2011