config_dir=smarty/smarty/config_file.class.php;
$this->caching=false; $this->template_dir = smarty/templates/; $this->cache_dir = smarty/smarty_cache/; $this->left_delimiter = {; $this->right_delimiter = }; }}?>
复制代码
2,adodb,连接数据库类:
class conndb{var $dbtype;var $host;var $user;var $pwd;var $dbname;var $debug;//false不显示侦错信息,反之,显示var $conn;function __construct($dbtype,$host,$user,$pwd,$dbname,$debug=false){ $this->dbtype = $dbtype; $this->host = $host; $this->user = $user; $this->pwd = $pwd; $this->dbname = $dbname; $this->debug = $debug;}//实现数据库的连接并返回连接对象(个人理解可以说返回adodb对象)function getconnid(){ include_once('adodb5/adodb.inc.php'); if($this->dbtype == mysql || $this->dbtype == mssql) {if($this->dbtype == mysql){ $this->conn = newadoconnection(mysql);//创建adodb对象,声明数据库类型为mysql}else { $this->conn = newadoconnection(mssql);}$this->conn->connect($this->host,$this->user,$this->pwd,$this->dbname); } else if($this->dbtype == access) {$this->conn = newadoconnection(access);$this->conn->connect(driver={microsoft access driver (*.mdb)};dbq=.$this->dbname.;uid=.$this->user.;pwd=.$this->pwd.;); } $this->conn->execute(set names utf-8); if($this->dbtype == mysql) {$this->conn->debug = $this->debug; } return $this->conn; }function closeconnid()//关闭与数据库的连接{ $this->conn->disconnection();}}
复制代码
3,数据库操作类:
class admindb{ var $sqlstr; var $conn; var $sqltype; var $rs; var $array; function execsql($sqlstr,$conn) {$rs = $conn->execute($sqlstr);$sqltype = strtolower(substr(trim($sqlstr),0,6)); //strtolower() 函数把字符串转换为小写。if($sqltype = select){ $array = $rs->getrows(); // 类似mysql_fetch_array函数返回的数组 if(count($array) == 0 || $rs == false) {return false; } else {return $array; }}else if($sqltype = update||$sqltype = insert||$sqltype = delete){ if($rs) {return true; } else {return false; }} }}
复制代码
4,分页类:
class seppage
{var $rs;var $pagesize;var $nowpage;var $array;var $conn;var $sqlstr;function showdate($sqlstr,$conn,$pagesize,$nowpage){ if(!isset($nowpage)||$nowpage==) {$nowpage = 1 ; } else {$this->nowpage = $nowpage; } $this->pagesize = $pagesize; $this->conn = $conn; $this->sqlstr = $sqlstr; $this->rs = $this->conn->pageexecute($this->sqlstr,$this->pagesize,$this->nowpage); //pageexecute($sql, $nrows, $page, $inputarr=false) 使用资料集的页码功能,叁数 $page 是以 1 为启使值$this->array = $this->rs->getrows();if(count($this->array) == 0 || $this->rs == false){ return false;}else { return $this->array;} }function showpage($contentname,$utits,$anothersearchstr,$class)
{ $allrs=$this->conn->execute($this->sqlstr);
$record=count($allrs->getrows()); $pagecount=ceil($record/$this->pagesize);
$str.=共有.$contentname. .$record. .$utits. 每页显示 .$this->pagesize. .$utits. 第 .$this->rs->absolutepage(). 页/共 .$pagecount. 页; $str.= ;
if(!$this->rs->atfirstpage())
{$str.=首页; } else {$str.=首页; } $str.= ; if(!$this->rs->atfirstpage())
{$str.=rs->absolutepage()-1).$anothersearchstr. class=.$class.>上一页; } else {$str.=上一页; } $str.= ; if(!$this->rs->atlastpage())
{$str.=rs->absolutepage()+1).$anothersearchstr. class=.$class.>下一页; } else {$str.=下一页; } $str.= ; if(!$this->rs->atlastpage())
{$str.=尾页; } else {$str.=尾页; } if(count($this->array)==0 || $this->rs==false) { return ; } else { return $str; } }}
复制代码
5,文章字符转换处理的类:
class usefun
{ function unhtml($text) {$content=(nl2br(htmlspecialchars($text)));//htmlspecialchars() 函数把一些预定义的字符转换为 html 实体,nl2br() 函数在字符串中的每个新行 (/n) 之前插入 html 换行符 (
)。$content=str_replace([strong],,$content);$content=str_replace([/strong],,$content);
$content=str_replace([em],,$content);$content=str_replace([/em],,$content);$content=str_replace([u],,$content);$content=str_replace([/u],,$content); $content=str_replace([font color=#ff0000],,$content);$content=str_replace([font color=#00ff00],,$content);$content=str_replace([font color=#0000ff],,$content); $content=str_replace([font face=楷体_gb2312],,$content);$content=str_replace([font face=宋体],,$content);$content=str_replace([font face=隶书],,$content); $content=str_replace([/font],,$content);//$content=str_replace(chr(32), ,$content);$content=str_replace([font size=1],,$content);$content=str_replace([font size=2],,$content);$content=str_replace([font size=3],,$content);$content=str_replace([font size=4],,$content); $content=str_replace([font size=5],,$content);$content=str_replace([font size=6],,$content);$content=str_replace([fieldset][legend],
,$content);$content=str_replace([/legend],,$content);$content=str_replace([/fieldset],,$content);return $content; }}
复制代码
将以上四个类全部放到一个类文件system.class.inc.php里.
另外几个文件:1、system.inc.php:
getconnid(); //数据库操作类实例化 $admindb = new admindb(); //分页类实例化 $seppage=new seppage(); //使用常用函数类实例化 $usefun=new usefun(); //调用smarty模板 $smarty=new smartyproject(); function unhtml($params) { extract($params); $text=$content; global $usefun; return $usefun->unhtml($text); } $smarty->register_function(unhtml,unhtml);
?>
复制代码
2、执行文件,index.php:
execsql(select * from tb_bookinfo,$conn);if(!$arraybbstell){ $smarty->assign(isbbstell,t);}else { $smarty->assign(isbbstell,t); $smarty->assign(arraybbstell,$arraybbstell);}$arraybbs = $seppage->showdate(select * from tb_bookinfo,$conn,1,$_get[page]);if(!$arraybbs){ $smarty->assign(isbbs,f); }else { $smarty->assign(isbbs,t); $smarty->assign(showpage,$seppage->showpage(帖子,条,,a1)); $smarty->assign(arraybbs,$arraybbs);}$smarty->display(index.html);?>
复制代码
3、解析文件,index.html:
椤垫ā
{if $isbbs==t}