--------------------------------------------------------------------------------
为了更明晰的熟悉,上面复杂的描写一下类库中的根基内容:(代码不完全)
--------------------------------------------------------------------------------
<?php
/**
* 文件:Type.class.php
* 功效:Type处置类
* 作者:heiyeluren
**/
class Type
{
var $mDsn;
var $mTableName;
var $hPearDB;
//机关函数
function Type()
{
//...
}
//取得pear DB类的句柄办法
function _getDBClass($fetchMode = DB_FETCHMODE_ASSOC)
{
if(!is_object($this->hPearDB)){
$this->hPearDB = DB::connect($this->mDsn);
$this->hPearDB->query("set names 'utf8'");
$this->hPearDB->setFetchMode($fetchMode);
if(DB::IsError($this->hPearDB)){
return false;
}
}
return $this->hPearDB;
}
//获得书本总数
function getBookTotal($TypeId)
{
$db = $this->_getDBClass();
$sql = "SELECT COUNT(*) AS total FROM ...";
$rs = $db->getOne($sql);
if (DB::isError($rs))
return $rs->getMessage();
else
return $rs;
}
//获得一切书本
function getBookFromType($TypeId, $start, $offset)
{
$db = $this->_getDBClass();
$sql = "SELECT * FROM ... LIMIT $start,$offset";
$rs = $db->getAll($sql);
if (DB::isError($rs))
return $rs->getMessage();
else
return $rs;
}
}
?>