-
-
include_once("smarty.class.php");
- class smartyproject extendmartssy
- >函數__construct()
- {
$this->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-🎜> $this- >right_delimiter = "}";
- }
- }
- ?>
-
-
複製程式碼
複製程式碼
2,dbdb ,連接資料庫類別:
-
-
-
- class conndb
- {
- var $dbtype;
- var $host;
- var $user
- var $🎜>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 = 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("設定名稱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( substrtolower( substr (修剪($sqlstr),0,6)); //strtolower() 函數把字串轉換為小寫。
- if($sqltype = "select")
- {
- $array = $rs->getrows(); // 類似mysql_fetch_array函數傳回的吞吐量
- if(count($array) = = 0 || $rs == false)
- {
- return false;
- }
- else
- {
- return $array;
- }
- }
- return $array;
- }
- }
- }
- else if($sqltype = "更新"||$sqltype = "插入"||$sqltype = "刪除")
- {
- if($rs)
{ 回傳true; } else {回傳false; }} } } 複製程式碼 複製程式碼 複製程式碼 複製碼🎜>
4,分頁類:
-
-
類間隔
- {
- 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); p>
- $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.=" "; p>
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;
- }
- }
- 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);
- return $content;
- }
- }
複製程式碼
將以上四個類別全部放到一個類別檔案system.class.inc.php裡.
另外幾個文件:
1、system.inc.php:
-
-
session_start();
- include_once("smarty_inc.php");
- include_once("smarty_inc.php"); ("system.class.inc.php");
- //資料庫連線類別實例化
- $connobj = new conndb("mysql","localhost","root","vertrigo","db_fenye" ,false);
- $conn = $connobj->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 global $usefun;
- return $usefun->unhtml($text );
- }
$smarty->register_function("unhtml","unhtml");
- ?>
複製程式碼
2、執行文件,index.php:
-
-
include_once("system.inc.php");
- $arraybbstell = $admindb->e.php");
- $arraybbstell = $admindb->e.php xecsql( " select * from tb_bookinfo",$conn);
- if(!$arraybbstell)
- {
- $smarty->assign("isbbstell","t");
- }
- else
- {
- $smarty->assign("isbbstell",t);
- $smarty->assign("arraybbstell",$arraybbstell);
- }
- $arraybbs = $arraybbs = $ seppage- >showdate("select * from tb_bookinfo",$conn,1,$_get["page"]);
- if(!$arraybbs)
- {
- $smarty->assign( "isbbs ", f);
-
- }
- else
- {
- $smarty->分配("isbbs",t);
- $smarty->分配(" showpage",$ seppage- >showpage("帖子","條","","a1"));
- $smarty->assign("arraybbs",$arraybbs);
- }
- $smarty-> display( "index.html");
?>
複製程式碼
3、解析文件,index.html:
-
- 页模
|
- {if $isbbs=="t"}
图书名称 |
图书内容 |
出版日期 |
图书作者 |
- {php}
- $i=1;
- {/php}
- {section name=bbsid loop=$arraybbs}
|
{unhtml content=$arraybbs[bbsid].bookname} |
{$arraybbs[bbsid].bookintro} |
{$arraybbs[bbsid].booktime} |
{$arraybbs[bbsid].bookauthor}
|
-
- {php}
- $i ;
- {/php}
- {/section}
-
-
-
-
-
-
|
-
-
-
-
-
-
-
-
-
{$showpage} |
-
-
|
-
- 表>
|
-
-
- {/if}
- {if $isbbstell=="f" && $isbbs=="f" }
-
- < ;tr>
{ldelim}暫時沒有內容{rdelim}字體> |
-
- table>
- {/if}
-
- > ;
-
|
-
-
-
- body>
陳述:本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn | | | |