| EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO |
|---|
| 7369 | SMITH | CLERK | 7902 | 80-12-17 | 800 | | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 81-02-20 | 1600 | 300 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 81-02-22 | 1250 | 500 | 30 |
| 7566 | JONES | MANAGER | 7839 | 81-04-02 | 2975 | | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 81-09-28 | 1250 | 1400 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 81-05-01 | 2850 | | 30 |
| 7782 | CLARK | MANAGER | 7839 | 81-06-09 | 2450 | | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 82-12-09 | 3000 | | 20 |
| 7839 | KING | PRESIDENT | | 81-11-17 | 5000 | | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 81-09-08 | 1500 | 0 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 83-01-12 | 1100 | | 20 |
| 7900 | JAMES | CLERK | 7698 | 81-12-03 | 950 | | 30 |
| 7902 | FORD | ANALYST | 7566 | 81-12-03 | 3000 | | 20 |
| 7934 | MILLER | CLERK | 7782 | 82-01-23 | 1300 | | 10 |
<?php
class Template
{
/**
* リソースを開く
*/
function open()
{
}
/**
* データを取得する
*/
function get()
{
}
/**
* 結果を表示する
*/
function show()
{
}
/**
* リソースを閉じる
*/
function close()
{
}
/**
* 処理の枠組み
*/
function process()
{
$this->open();
$this->get();
$this->show();
$this->close();
}
}
/**
* DBデータの表示
*/
class DbDisplay extends Template
{
var $conn_;
var $stmt_;
var $data_;
var $rows_;
function open()
{
$this->conn_ = OCILogon("scott", "tiger", "orcl");
}
function get()
{
$this->stmt_ = OCIParse($this->conn_, "SELECT * FROM emp");
OCIExecute($this->stmt_);
$this->rows_ = OCIFetchStatement($this->stmt_, $this->data_);
}
function show()
{
echo "<table border=\"1\">";
echo "<tr>";
while (list( $key, $val ) = each( $this->data_ ) ) {
echo "<th>$key</th>";
}
echo "</tr>";
for ( $i = 0; $i < $this->rows_; $i++ ) {
reset($this->data_);
echo "<tr>";
while ( $column = each($this->data_) ) {
$data = $column['value'];
echo "<td>$data[$i]</td>";
}
echo "</tr>";
}
echo "</table>";
}
function close()
{
OCIFreeStatement($this->stmt_);
OCILogOff($this->conn_);
}
}
/**
* ファイルデータの表示
*/
class FileDisplay extends Template
{
var $fp_;
var $buf_;
function open()
{
$this->fp_ = fopen(__FILE__, "r");
}
function get()
{
while (!feof($this->fp_)) {
$this->buf_ .= fgets($this->fp_, 4096);
}
}
function show()
{
highlight_string($this->buf_);
}
function close()
{
fclose($this->fp_);
}
}
?>
<?php
/**
* main
*/
$arr = array(new DbDisplay(), new FileDisplay());
foreach ($arr as $index => $obj) {
$obj->process();
echo "<hr>";
}
?>