abstract class Executor { protected $mdb2_; public function __construct() { //$dsn = $cfg['db']['dsn']; $this->mdb2_ = &MDB2::singleton('mysqli://root:admin@ess-4/eduLC'); if (PEAR::isError($this->mdb2_)) { throw new Exception($this->mdb2_->getMessage(), $this->mdb2_->getCode()); } } } class StoredProcExecutor extends Executor { private $rs_; public function & query($name, $params = null) { $this->mdb2_->loadModule('Function'); $this->rs_ = &$this->mdb2_->executeStoredProc($name, $params); if (PEAR::isError($this->rs_)) { throw new Exception($this->rs_->getMessage(), $this->rs_->getCode()); } return $this->rs_; } public function __destruct() { if ($this->rs_ != null) $this->rs_->free(); } } function execSelectSP() { $sqe = new StoredProcExecutor(); $param = array(1); $res = &$sqe->query('sample', $param); while (($row = $res->fetchRow())) { echo $row[0] . ' | ' . $row[1] . ' | ' . $row[2] . '
'; } $sqe = null; } function execSelectSP1() { $qe = new QueryExecutor(); $sql = 'call sample(?)'; $intypes = array('integer'); $qe->prepare($sql, $intypes); $values = array(1); $res = &$qe->exec($values); while (($row = $res->fetchRow())) { echo $row[0] . ' | ' . $row[1] . ' | ' . $row[2] . '
'; } $qe = null; }