<?php

include_once "DB.php";

$dbo = new DB;
$dbo->dbconnect();

$q = oci_parse($dbo->db, "select * from employees");

$r = oci_execute($q, OCI_DEFAULT);

print "Return $r\n";

$ncols = oci_num_fields($q);

for ($i = 1; $i <= $ncols; $i++) {
    $column_name  = oci_field_name($q, $i);    
    $trow[] = $column_name;    
}
$table[] = $trow;

while ($row = oci_fetch_array($q, OCI_ASSOC+OCI_RETURN_NULLS)) {
  $table[] = $row;  
}

$dbo->print_table($table);
?>
<?php

ini_set('display_errors', 1);

class DB {
  public $db;
 
  function dbconnect() {
    $this->db = oci_connect('hr', 'hr', 'orcl');  
  }  


 function print_table($table) {
 print "<table border=1>\n";
 foreach ($table as $row) {
  print "<tr>"; 
  foreach ($row as $cell) {
    if (!isset($cell)) {$cell = 'n/a'; }  	
    print "<td> $cell </td> ";
  }
  print "</tr>\n";
  } 

 print "</table>\n";
 }
}
?>
<?php

require_once('DB.php');

class DB_Error extends DB {
  function dbconnect() {
    parent::dbconnect();
	if (!$this->db) {print "Problem\n"; exit;}
  }
}
?>