<html>
<head>
<title>Test PHP Database Connection to Oracle</title>
</head>
<body>
<h1>Test PHP Database Connection to Oracle</h1>

<?php

    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);

    $host = 'localhost';
    $db   = 'ORCL';
    $user = 'demo';
    $pswd = 'demo';    

    $output=null;
    $retval=null;
    exec('whoami', $output, $retval);

    print("<br><b>Attempting to connect to Oracle server on: $host and $db ...</b><br>\n");
    print("<b>Running under userid... </b>" . $output[0] . "<br><br>\n");

    // Connect to Oracle database server -------------------------------------

    $host_db = $host . '/' . $db;

    $env = getenv();
    print("<b>ENVIRONMENT VARIABLES...</b><br> \n");
    print("<table border=1> \n");
    foreach ($env as $k=>$v) 
        print "<tr><td><b> $k <td> $v </tr> \n";
    print('</table><br>');
 
    $connect = oci_connect($user,$pswd,$host_db);
    if (! $connect) {
	$error = oci_error();
//      print_r($error);                               		//print the entire array
        die('Could not connect: ' . $error['message']);
    }
    print("<b>Connected to DB server on: $host</b><br>");
    print("<b>Database selected: $db</b><br><br>");

    // perform select query -------------------------------------------------

    $stmt   = oci_parse($connect, 'select fname, lname, ssn from student');
    if (! $stmt) {
	$error = oci_error($connect);
        die('Could not parse statement: ' . $error['message']);
    }
    $result = oci_execute($stmt);
    if (! $result) {
	$error = oci_error($stmt);
        die('Could not execute query: ' . $error['message']);
    }
    while ($row = oci_fetch_assoc($stmt)) {
        echo $row['FNAME'],' ',$row['LNAME'],' ',$row['SSN'],"<br>\n";
    }

    // release resources ----------------------------------------------------

    oci_free_statement($stmt);

    oci_close($connect);
?>

</body>
</html>