<?php  session_start(); //must be at beginning ?>

<html>
<head>
<title>PHP Oracle client</title>
</head>

<!-- presents generic Oracle prompt on browser -->

<body onload="document.forms[0].elements[0].focus();">


<?php
//initial page load.  get username and password.   https or not???
if ($_SERVER['REQUEST_METHOD'] == 'GET'): ?>
login to Oracle database server:<br>
<form name="loginForm" action="http://<?php echo $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'?>" method="post">
Username:
<input type="text" size="12" maxlength="20"  name="username">
<br>
Password:
<input type="password" size="12" maxlength="30"  name="password">
<br>
<input name="login" value="Login" type="submit">
</form>
</body>
</html>
<?php
$_SESSION
['firstposting'] = true;  //HTTP_SESSION_VARS is pre 4.1
exit();  
endif;
?>


<?php
if ($_SESSION['firstposting']) {
  
$_SESSION['username'] = $_POST['username'];
  
$_SESSION['password'] = $_POST['password'];
  
$_SESSION['curr_DB'] = "";
  
$_SESSION['queryHistory'] = "";     // \0 delimited fields
  
$_SESSION['firstposting'] = false;
}

//echo "username: ".$_SESSION['username']."   password: ".$_SESSION['password'];
$dbcnx oci_connect($_SESSION['username'], $_SESSION['password'],'//localhost/XE');

if (!
$dbcnx) {
  echo 
"<p>Unable to connect to the database server.</p>";
  exit();
}
?>


<form name="queryForm" action="http://<?php echo $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'?>" method="post">
/*<?php
//echo "MySQL Server ".mysql_get_server_info();
//echo "@ ".mysql_get_host_info();
//echo "&nbsp;&nbsp;&nbsp;Client: ".mysql_get_client_info();
?>*/
<br>
Oracle server command-&gt;
<br>
<textarea name="cmd" rows="5" cols="100" wrap="hard"><?php echo $_POST['cmd'?></textarea>
<br>
Query history: 
<select name="previousQueries" 
onChange="document.queryForm.cmd.value =  document.queryForm.previousQueries.options[document.queryForm.previousQueries.selectedIndex].value;">
<?php
$history 
explode('\0',$_SESSION['queryHistory']);
$histsize count($history);
for (
$i=$histsize-1$i>=0$i--)
     echo 
"<option>".$history[$i]."</option>\n";
?>
</select>
<br>
<input type="submit">    <!-- if this is before select, the onChange does not work?!?! -->
</form>

<?php
$_POST
['cmd'] = trim($_POST['cmd']);

if (
strlen($_POST['cmd'])>0) {
    echo 
"<hr>\n";
    
$stid oci_parse($dbcnx$_POST['cmd']);
    if (!
$stid
      echo 
"<P>Error parsing query: ".$_POST['cmd']."<br></P>";
    else {
      
$result oci_execute($stidOCI_DEFAULT);
      if (!
$result
        echo 
"<P>Error executing query: ".$_POST['cmd']."<br></P>";
      else {
      echo 
"<h3>".$_POST['cmd']."</h3>\n";
      echo(
"<table border=1>\n");
/*      echo("<tr>");
      for ($i=0; $i<oci_num_fields($result); $i++) {
    echo "<th>".oci_field_name($result,$i)."</th>";
      }
      echo("</tr>\n");
*/
      
while ($row oci_fetch_array($stidOCI_RETURN_NULLS)) {
        echo 
"<tr>";
        foreach (
$row as $item) {
          echo 
"<td>".($item htmlentities($item) : '&nbsp;')."</td>";
        }
        echo 
"</tr>\n";
      }
      echo 
"</table>\n";
      
$_SESSION['queryHistory'] .= '\0'.$_POST['cmd'];    //add to history
    
}
  }
}
?>


</body>
</html>