I've got quite a mess here.

I have a new Windows 2000 Server, running IIS. I've installed PHP manually (as well as using the php.net binaries). I have edited the php.ini file to point the extension_dir to the correct location. I have installed the Oracle client, as well as SQL Plus.

I also have an UNIX box, running the actual Oracle db.

No matter what I try, I cannot connect to the DB through a PHP script. I have now tried 3 different approaches (scripts) with no luck. The scripts, along with their errors, are below.

As a side note, when I try to uncomment oci8.dll or oracle.dll in the php.ini file, i can no longer get PHP to function. it just sits there. Perhaps this is the real problem?

Lastly, when I try to connect to the Oracle DB from the Windows server through SQL Plus, it works great.

Code try number 1:

$dsn = 'will';
$dbuser = 'plsowner';
$dbpass = 'skypiepls4';
$dbname = 'sky';

function dbConnect() {
    global $dsn, $dbuser, $dbpass;

$dbcnx = odbc_connect($dsn, $dbuser, $dbpass)
    or die('The site database appears to be down..');

if ($db!='')
    die('The site database is unavailable.');

return $dbcnx;
}
dbConnect($dbname); ?>

Error: PHP Warning: odbc_connect(): SQL error: [Microsoft][ODBC driver for Oracle][Oracle]ORA-12154: TNS:could not resolve service name, SQL state 08001 in SQLConnect in C:\Inetpub\wwwroot\projects\PLS\PHP_DEV\db.php on line 12

Try number two:

dl('php_oracle.dll');
//dl('php_oci8.dll');
putenv("ORACLE_SID=pie");
if ($c=ocilogon("plsowner", "skypiepls4")) {
  echo "Successfully connected to Oracle.\n";
  OCILogoff($c);
} else {
  $err = ocierror();
  echo "Oracle Connect Error " . $err[text];
} ?>

Error: (times out)

Try number 3:

$odbc=odbc_connect('sky', 'plsowner', 'skypiepls4') or die("could not connect to odbc db:".odbc_error()."<P>");

function odbc_fetch_array($result, $rownumber=-1) { 
    if (PHP_VERSION > "4.1") { 
        if ($rownumber < 0) { 
            odbc_fetch_into($result, $rs); 
        } else { 
            odbc_fetch_into($result, $rs, $rownumber); 
        } 
    } else { 
        odbc_fetch_into($result, $rownumber, $rs); 
    } 

$rs_assoc = Array(); 

foreach ($rs as $key => $value) { 
    $rs_assoc[odbc_field_name($result, $key+1)] = $value; 
} 
return $rs_assoc; 
} 
?> 

Error:
could not connect to odbc db:S1009
PHP Warning: odbc_connect(): SQL error: [Oracle][ODBC][Rdb]Invalid argument value., SQL state S1009 in SQLConnect in C:\Inetpub\wwwroot\projects\PLS\PHP_DEV\odbc.php on line 2

Help!

    I don't have W2k Server, just Pro. I just uncommented the extension=php_oracle.dll line and I've been able to connect to our Oracle databases. Uncommenting extension=php_oci8.dll along ith php_oracle.dll will cause errors (documented on php.net, I think - you can use one or the other but not both). You'll want to make sure one of the DLL's is in the system path so I had to move them into one of the winnt subdirectories (I think I moved mine to system32). Or you could just add a directory to the path environment variable.

    Then run phpinfo() and see if Oracle comes up.

    Over here, I have to add an entry for all the databases I wish to talk to in TNSNAMES.ORA. If you were able to talk to your database via SQL Plus, then I'd assume you're all set on this.

    After that, I'm not sure what to recommend...

      8 days later

      Running phpinfo() shows me that Oracle is enabled. Also, as you mentioned, I assume TNSNAMES.ora is working just fine since I can connect via SQL Plus. Very odd, this one.

      An uninstall and reinstall of PHP and Oracle does not change this at all.

      I've also found that commenting out oracle.dll seems to not crash the system, but the minute I comment out oci8.dll, the entire website grinds to a halt.

        I had the same problem and corrected it by supplying the following at the beginning of the script:

        putenv("TNS_ADMIN=C:\TNSNAMES");

        Also make sure that the entry in TNSNAMES.ORA is correctly formated for the connection you are attempting to make.

          since there is no C:\TNSNAMES folder, would I be correct in assuming I can use this verbage?

          putenv ("TNS_ADMIN=C:\ORANT\NET80\ADMIN\TNSNAMES");

          Will

            You are correct.
            It's just the location of where the TNSNAMES.ORA file is located.

            Mine just happened to be in C:\TNSNAMES.

            William

              Would you mind sharing your connection code? I've tried variations of the three listed at the beginning of this thread, all with no luck...

              Also, should I have the oci8.dll commented out or not? I've read that it may be better to use the d() option. Any comments?

                Will,

                I am loading oci8.dll in my php.ini file.

                Here's the abreviated code of the script:

                <?

                putenv("TNS_ADMIN=C:\TNSNAMES");

                //connect to Database
                //dbname is the name defined in TNSNAMES.ORA for the connection.
                $conn = ocilogon('user','password','dbname');

                //create the cursor
                $cursor = ocinewcursor($conn);

                $query = "SELECT DISTINCT C_SW_TITLE.TITLE_ID AS TITLEID, ..... ;";

                //parse query
                $stmt = ociparse($conn, $query);

                OCIDefineByName($stmt, "TITLEID", $kbrid);
                OCIDefineByName(....... ;

                if(!($dbResult = ociexecute($stmt, OCI_DEFAULT)))
                {
                print("Could not execute query!<br>\n");
                echo "ocierror()";
                exit();
                }

                .......

                ?>

                Let me know if this helps. The remainder of the code simply takes the result of the query and generates a web page table to show the results.

                William

                  This MAY help...dunno how old or relevant it is

                  here is an article from oralce itslelf

                  and this is another

                    Write a Reply...