EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO
7369SMITHCLERK790280-12-1780020
7499ALLENSALESMAN769881-02-20160030030
7521WARDSALESMAN769881-02-22125050030
7566JONESMANAGER783981-04-02297520
7654MARTINSALESMAN769881-09-281250140030
7698BLAKEMANAGER783981-05-01285030
7782CLARKMANAGER783981-06-09245010
7788SCOTTANALYST756682-12-09300020
7839KINGPRESIDENT81-11-17500010
7844TURNERSALESMAN769881-09-081500030
7876ADAMSCLERK778883-01-12110020
7900JAMESCLERK769881-12-0395030
7902FORDANALYST756681-12-03300020
7934MILLERCLERK778282-01-23130010
93下岡秀幸ソフト

<?php
require_once("jp/ne/hi_ho/pat/dimension/Abstract.phl");
?>
<?php
class Director
{
    var 
$builder_;

    
/**
     * リソースを開く
     */
    
function Director($builder)
    {
        
$this->builder_ $builder;
    }

    
/**
     * データを作成し、返す
     */
    
function construct()
    {
        
$this->builder_->open();
        
$this->builder_->get();
        
$this->builder_->make();
        
$this->builder_->close();

        return 
$this->builder_->getResult();
    }
}

class 
Builder
{
    
/**
     * リソースを開く
     */
    
function open() { Abstract::set("open"); }

    
/**
     * データを取得する
     */
    
function get() { Abstract::set("get"); }

    
/**
     * 結果を作成する
     */
    
function make() { Abstract::set("make"); }

    
/**
     * リソースを閉じる
     */
    
function close() { Abstract::set("close"); }

    
/**
     * 結果を返す
     */
    
function getResult() { Abstract::set("getResult"); }

}

/**
* DBデータの表示
*/
class DbBuilder extends Builder
{
    
// 結果文字列を格納するバッファ
    
var $buf_;

    var 
$conn_;
    var 
$stmt_;
    var 
$data_;
    var 
$rows_;

    function 
open()
    {
        
$this->conn_ OCILogon("scott""tiger""orcl");
        
$this->buf_ "";
    }

    function 
get()
    {
        
$this->stmt_ OCIParse($this->conn_"SELECT * FROM emp");
        
OCIExecute($this->stmt_);
        
$this->rows_ OCIFetchStatement($this->stmt_$this->data_);
    }

    function 
make()
    {
        
$this->buf_ .= "<table border=\"1\">";
        
$this->buf_ .= "<tr>";
        while (list( 
$key$val ) = each$this->data_ ) ) {
            
$this->buf_ .= "<th>$key</th>";
        }
        
$this->buf_ .= "</tr>";

        for ( 
$i 0$i $this->rows_$i++ ) {
            
reset($this->data_);
            
$this->buf_ .= "<tr>";
            while ( 
$column each($this->data_) ) {
                
$data $column['value'];
                
$this->buf_ .= "<td>$data[$i]</td>";
            }
            
$this->buf_ .= "</tr>";
        }
        
$this->buf_ .= "</table>";
    }

    function 
close()
    {
        
OCIFreeStatement($this->stmt_);
        
OCILogOff($this->conn_);
    }

    function 
getResult() { return $this->buf_; }
}
/**
* ファイルデータの表示
*/
class FileBuilder extends Builder
{
    var 
$fp_;
    var 
$buf_;

    function 
open()
    {
        
$this->fp_ fopen(__FILE__"r");
        
$this->buf_ "";
    }

    function 
get()
    {
        while (!
feof($this->fp_)) {
            
$this->buf_ .= fgets($this->fp_4096);
        }
    }

    function 
make()
    {
        
$this->buf_ highlight_string($this->buf_);
    }

    function 
close()
    {
        
fclose($this->fp_);
    }

    function 
getResult() { return $this->buf_; }
}
?>
<?php
    
/**
     * main
     */
    
$arr = array(new DbBuilder(), new FileBuilder());
    foreach (
$arr as $index => $obj) {
        
$director = new Director($obj);
        echo 
$director->construct();
        echo 
"<hr>";
    }
?>
1