<?php

class Sample
{
    var 
$conn;                // ?f?[?^?x?[?X??R?l?N?V????
    
var $rows;                // ???????i?[?p?z?
    
    
function Sample($user$passwd)    // connect Oracle DB
    
{
        if(
$this->conn OCILogon($user$passwd)) {
            return(
TRUE);
        } else {
            return(
FALSE);
        }
    }
    
    function 
logoff()    // disconnect Oracle DB
    
{
        
OCILogoff($this->conn);
    }
    
    function 
selectExec($sql)    // select???s
    
{
        if((
$conn $this->conn) == FALSE) return(FALSE);
        
        
$this->rows = array();
        
$arr = array();
        
$stmt OCIParse($conn$sql);
        if(
OCIExecute($stmtOCI_DEFAULT) ) {
            while(
OCIFetchInto($stmt, &$arrOCI_ASSOC)) {
                
$this->rows[] = $arr;
            }
            
            
OCIFreeStatement($stmt);
            return(
TRUE);
        } else {
            return(
FALSE);
        }
    }
    
    function 
getEmp()        // SELECT * FROM EMP
    
{
        
$sql "select * from emp";
        return(
$this->selectExec($sql));
    }

    function 
getDept()        // SELECT * FROM DEPT
    
{
        
$sql "select * from dept";
        return(
$this->selectExec($sql));
    }
}

function 
viewTable($arr)
{
    echo 
"<table border=1>\n";
    while(list(
$c$row) = each($arr)) {
        echo 
"<tr>\n";
        while(list(
$col$value) = each($row)) {
            echo 
"<td>$value</td>\n";
        }
        echo 
"</tr>\n";
    }
    echo 
"</table>\n";
}

function 
viewEMP($arr)
{
    echo 
"<table border=1>\n";
    echo 
"<tr><th>EMPNO</th><th>ENAME</th><th>JOB</th><th>HIREDATE</th></tr>\n";
    while(list(
$c$row) = each($arr)) {
        echo 
"<tr>\n";
        echo 
"<td>"$row['EMPNO'] ."</td>\n";
        echo 
"<td>"$row['ENAME'] ."</td>\n";
        echo 
"<td>"$row['JOB'] ."</td>\n";
        echo 
"<td>"$row['HIREDATE'] ."</td>\n";
        echo 
"</tr>\n";
    }
    echo 
"</table>\n";
}
?>

<html>
<head><title>Example:PHP Class</title></head>
<body>
<?php

if($scott = new Sample("scott""tiger")) {
    
// EMP ?\??\Ž¦??
    
if($scott->getEmp()) {
//        viewTable($scott->rows);
        
viewEMP($scott->rows);    // EMP ?\?\Ž¦???
    
}
    
// DEPT ?\??\Ž¦??
    
if($scott->getDept()) {
        
viewTable($scott->rows);
    }

    
$scott->logoff();
}
?>
</body>
</html>