1 <?php
2 //数据库连接类
3 class ConnDB{
4
5 var $dbtype;
6 var $host;
7 var $user;
8 var $pwd;
9 var $dbname;
10
11 //构造方法
12 function ConnDB($dbtype,$host,$user,$pwd,$dbname){
13 $this->dbtype=$dbtype;
14 $this->host=$host;
15 $this->user=$user;
16 $this->pwd=$pwd;
17 $this->dbname=$dbname;
18 }
19
20 //实现数据库的连接并返回连接对象
21 function GetConnId(){
22
23 if($this->dbtype=="mysql" || $this->dbtype=="mssql"){
24 $dsn="$this->dbtype:host=$this->host;dbname=$this->dbname";
25 }else{
26 $dsn="$this->dbtype:dbname=$this->dbname";
27 }
28 try {
29 $conn = new PDO($dsn, $this->user, $this->pwd); //初始化一个PDO对象,就是创建了数据库连接对象$pdo
30 $conn->query("set names utf8");
31 return $conn;
32 } catch (PDOException $e) {
33 die ("Error!: " . $e->getMessage() . "<br/>");
34 }
35
36
37 }
38 }
39
40 //数据库管理类
41 class AdminDB{
42
43
44 function ExecSQL($sqlstr,$conn){
45
46 $sqltype=strtolower(substr(trim($sqlstr),0,6));
47 $rs=$conn->prepare($sqlstr); //准备查询语句
48 $rs->execute(); //执行查询语句,并返回结果集
49 if($sqltype=="select"){
50 $array=$rs->fetchAll(PDO::FETCH_ASSOC); //获取结果集中的所有数据
51 if(count($array)==0 || $rs==false)
52 return false;
53 else
54 return $array;
55 }elseif ($sqltype=="update" || $sqltype=="insert" || $sqltype=="delete"){
56 if($rs)
57 return true;
58 else
59 return false;
60 }
61 }
62 }
63 //分页类
64 class SepPage{
65 var $rs;
66 var $pagesize;
67 var $nowpage;
68 var $array;
69 var $conn;
70 var $sqlstr;
71 function ShowData($sqlstr,$conn,$pagesize,$nowpage){ //定义方法
72 if(!isset($nowpage) || $nowpage=="") //判断变量值是否为空
73 $this->nowpage=1; //定义每页起始页
74 else
75 $this->nowpage=$nowpage;
76 $this->pagesize=$pagesize; //定义每页输出的记录数
77 $this->conn=$conn; //连接数据库返回的标识
78 $this->sqlstr=$sqlstr; //执行的查询语句
79 $offset=($this->nowpage-1)*$this->pagesize;
80 $sql=$this->sqlstr." limit $offset, $this->pagesize";
81 $result=$this->conn->prepare($sql); //准备查询语句
82 $result->execute(); //执行查询语句,并返回结果集
83 $this->array=$result->fetchAll(PDO::FETCH_ASSOC); //获取结果集中的所有数据
84 if(count($this->array)==0 || $this->array==false)
85 return false;
86 else
87 return $this->array;
88 }
89
90 function ShowPage($contentname,$utits,$anothersearchstr,$anothersearchstrs,$class){
91 $str="";
92 $res=$this->conn->prepare($this->sqlstr); //准备查询语句
93 $res->execute(); //执行查询语句,并返回结果集
94 $this->array=$res->fetchAll(PDO::FETCH_ASSOC); //获取结果集中的所有数据
95 $record=count($this->array); //统计记录总数
96
97 $pagecount=ceil($record/$this->pagesize); //计算共有几页
98 $str.=$contentname." ".$record." ".$utits." 每页 ".$this->pagesize." ".$utits." 第 ".$this->nowpage." 页/共 ".$pagecount." 页";
99 $str.=" ";
100 if($this->nowpage!=1)
101 $str.="<a href=".$_SERVER[‘PHP_SELF‘]."?page=1&page_type=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">首页</a>";
102 else
103 $str.="<font color=‘#555555‘>首页</font>";
104 $str.=" ";
105 if($this->nowpage!=1)
106 $str.="<a href=".$_SERVER[‘PHP_SELF‘]."?page=".($this->nowpage-1)."&page_type=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">上一页</a>";
107 else
108 $str.="<font color=‘#555555‘>上一页</font>";
109 $str.=" ";
110 if($this->nowpage!=$pagecount)
111 $str.="<a href=".$_SERVER[‘PHP_SELF‘]."?page=".($this->nowpage+1)."&page_type=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">下一页</a>";
112 else
113 $str.="<font color=‘#555555‘>下一页</font>";
114 $str.=" ";
115 if($this->nowpage!=$pagecount)
116 $str.="<a href=".$_SERVER[‘PHP_SELF‘]."?page=".$pagecount."&page_type=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">尾页</a>";
117 else
118 $str.="<font color=‘#555555‘>尾页</font>";
119 if(count($this->array)==0 || $this->array==false)
120 return "无数据!";
121 else
122 return $str;
123 }
124 }
125 //系统常用方法
126 class UseFun{
127
128 function UnHtml($text){
129 $content=(nl2br(htmlspecialchars($text)));
130 $content=str_replace("[strong]","<strong>",$content);
131 $content=str_replace("[/strong]","</strong>",$content);
132 $content=str_replace("[em]","<em>",$content);
133 $content=str_replace("[/em]","</em>",$content);
134 $content=str_replace("[u]","<u>",$content);
135 $content=str_replace("[/u]","</u>",$content);
136
137
138 $content=str_replace("[font color=#FF0000]","<font color=#FF0000>",$content);
139 $content=str_replace("[font color=#00FF00]","<font color=#00FF00>",$content);
140 $content=str_replace("[font color=#0000FF]","<font color=#0000FF>",$content);
141
142 $content=str_replace("[font face=楷体_GB2312]","<font face=楷体_GB2312>",$content);
143 $content=str_replace("[font face=宋体]","<font face=新宋体>",$content);
144 $content=str_replace("[font face=隶书]","<font face=隶书>",$content);
145 $content=str_replace("[/font]","</font>",$content);
146 //$content=str_replace(chr(32)," ",$content);
147 $content=str_replace("[font size=1]","<font size=1>",$content);
148 $content=str_replace("[font size=2]","<font size=2>",$content);
149 $content=str_replace("[font size=3]","<font size=3>",$content);
150 $content=str_replace("[font size=4]","<font size=4>",$content);
151 $content=str_replace("[font size=5]","<font size=5>",$content);
152 $content=str_replace("[font size=6]","<font size=6>",$content);
153
154 $content=str_replace("[FIELDSET][LEGEND]","<FIELDSET><LEGEND>",$content);
155 $content=str_replace("[/LEGEND]","</LEGEND>",$content);
156 $content=str_replace("[/FIELDSET]","</FIELDSET>",$content);
157 return $content;
158 }
159
160 }
161
162 ?>