conn = OCILogon($user, $passwd)) {
return(TRUE);
} else {
return(FALSE);
}
}
function logoff() // disconnect Oracle DB
{
OCILogoff($this->conn);
}
function selectExec($sql) // select文実行
{
if(($conn = $this->conn) == FALSE) return(FALSE);
$this->rows = array();
$arr = array();
$stmt = OCIParse($conn, $sql);
if(OCIExecute($stmt, OCI_DEFAULT) ) {
while(OCIFetchInto($stmt, &$arr, OCI_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 "
\n";
while(list($c, $row) = each($arr)) {
echo "\n";
while(list($col, $value) = each($row)) {
echo "| $value | \n";
}
echo "
\n";
}
echo "
\n";
}
function viewEMP($arr)
{
echo "\n";
echo "| EMPNO | ENAME | JOB | HIREDATE |
\n";
while(list($c, $row) = each($arr)) {
echo "\n";
echo "| ". $row['EMPNO'] ." | \n";
echo "". $row['ENAME'] ." | \n";
echo "". $row['JOB'] ." | \n";
echo "". $row['HIREDATE'] ." | \n";
echo "
\n";
}
echo "
\n";
}
?>
Example:PHP Class
getEmp()) {
// viewTable($scott->rows);
viewEMP($scott->rows); // EMP 表表示関数
}
// DEPT 表を表示する
if($scott->getDept()) {
viewTable($scott->rows);
}
$scott->logoff();
}
?>