This discussion is archived
1 Reply Latest reply: Feb 12, 2013 11:30 AM by cj RSS

Oracle oci8 problem: OCIEnvNlsCreate() failed

Nick2005 Newbie
Currently Being Moderated
Hi to all,
I have installed Apache 2.4.3, PHP 5.3.21 and Oracle Database 10gR2 on a Windows 2003 server. Please that is installed the complete Oracle DB* and not the only Oracle Client.
When I run phpinfo This is the result:
OCI8 Support      enabled
Version      1.4.9
Revision      $Id: 44bfa713983a99b3e59477f6532e5fb51b6dee94 $
Active Persistent Connections      0
Active Connections      0
Oracle Run-time Client Library Version      0.0.0.0.0
Oracle Instant Client Version      10.2
Temporary Lob support      enabled
Collections support      enabled
Directive     Local Value     Master Value
oci8.connection_class     no value     no value
oci8.default_prefetch     100     100
oci8.events     Off     Off
oci8.max_persistent     -1     -1
oci8.old_oci_close_semantics     Off     Off
oci8.persistent_timeout     -1     -1
oci8.ping_interval     60     60
oci8.privileged_connect     Off     Off
oci8.statement_cache_size     20     20
I have create a file connect.php in order to test my connection:
<?php 

$dbHost = "win2003vm";
$dbHostPort="1521";
$dbServiceName = "myservice";
$usr = "myuser";
$pswd = "mypwd";
$dbConnStr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
            (HOST=".$dbHost.")(PORT=".$dbHostPort."))
            (CONNECT_DATA=(SERVICE_NAME=".$dbServiceName.")))";


if(!$dbConn = oci_connect($usr,$pswd,$dbConnStr)){
$err = oci_error();
trigger_error('connection failed: ' . $err['message'], E_USER_ERROR);
};

$strSQL = "SELECT SYSDATE FROM DUAL";

$stmt = oci_parse($dbConn,$strSQL);
if ( ! oci_execute($stmt) ){
$err = oci_error($stmt);
trigger_error('Query failed: ' . $err['message'], E_USER_ERROR);
};

while(oci_fetch($stmt)){
    $rslt = oci_result($stmt, 1); print "<h3>Query result: ".$rslt."</h3>";
}
?>
But when I run the php file, this error is displayed:
Warning: oci_connect(): OCIEnvNlsCreate() failed. There is something wrong with your system - please check that PATH includes the directory with Oracle Instant Client libraries in C:\www\win2003vm\connect.php on line 13 Fatal error
Can someone help me ?
Thank You and best regards
Gaetano
  • 1. Re: Oracle oci8 problem: OCIEnvNlsCreate() failed
    cj Employee ACE
    Currently Being Moderated
    The reason the error mentions Instant Client is because this text was
    compiled into the DLL when it was built using Instant Client. You can
    ignore this message phrasing quirk and focus on why OCIEnvNlsCreate()
    failed. Seeing the C code might help explain why the 'wrong' text is
    shown:
         errstatus = OCIEnvNlsCreate(&OCI_G(env), PHP_OCI_INIT_MODE, 0, NULL, NULL, NULL, 0, NULL, 0, 0);
    
         if (errstatus == OCI_ERROR) {
    #ifdef HAVE_OCI_INSTANT_CLIENT
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "OCIEnvNlsCreate() failed. There is something wrong with your system - please check that " PHP_OCI8_LIB_PATH_MSG " includes the directory with Oracle Instant Client libraries");
    #else
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "OCIEnvNlsCreate() failed. There is something wrong with your system - please check that ORACLE_HOME and " PHP_OCI8_LIB_PATH_MSG " are set and point to the right directories");
                    . . . 
    #endif
    Do you have other Oracle libraries that are causing a library clash?
    Did you reboot after installing? Is there some permission issue with
    the web server environment? Are you using Apache or ISS. Does this
    help:
    https://blogs.oracle.com/opal/entry/how_to_use_iis_php_and_oracle

    Also see "Commonly Seen Connection and Environment Errors" on p 107 of
    http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html

    You may be interested that your $dbConnStr can be simplified. See
    "Easy Connect String" on p 104 of the above book. The variable can be:
    $dbConnStr = "${dbHost}:${dbHostPort}/${dbServiceName}";
    In fact, since you are using the default port, it could even be just:
    $dbConnStr = "${dbHost}/${dbServiceName}";

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points