1. 云栖社区>
  2. PHP教程>
  3. 正文

php模块参考

作者:用户 来源:互联网 时间:2017-12-01 12:35:23

模块参考

php模块参考 - 摘要: 本文讲的是php模块参考, 1 <?php 2 //数据库连接类 3 class ConnDB{ 4 5 var $dbtype; 6 var $host; 7 var $user; 8 var $p

  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."&nbsp;".$record."&nbsp;".$utits."&nbsp;每页&nbsp;".$this->pagesize."&nbsp;".$utits."&nbsp;第&nbsp;".$this->nowpage."&nbsp;页/共&nbsp;".$pagecount."&nbsp;页"; 99         $str.="&nbsp;&nbsp;&nbsp;&nbsp;";100         if($this->nowpage!=1)101             $str.="<a href=".$_SERVER['PHP_SELF']."?page=1&page_type=".$anothersearchstr."&parameter2=".$anothersearchstrs." class=".$class.">首页</a>";102         else103             $str.="<font color='#555555'>首页</font>";104         $str.="&nbsp;";105         if($this->nowpage!=1)106             $str.="<a href=".$_SERVER['PHP_SELF']."?page=".($this->nowpage-1)."&page_type=".$anothersearchstr."&parameter2=".$anothersearchstrs." class=".$class.">上一页</a>";107         else108             $str.="<font color='#555555'>上一页</font>";109         $str.="&nbsp;";    110         if($this->nowpage!=$pagecount)111             $str.="<a href=".$_SERVER['PHP_SELF']."?page=".($this->nowpage+1)."&page_type=".$anothersearchstr."&parameter2=".$anothersearchstrs." class=".$class.">下一页</a>";112         else113             $str.="<font color='#555555'>下一页</font>";    114         $str.="&nbsp;";115         if($this->nowpage!=$pagecount)116             $str.="<a href=".$_SERVER['PHP_SELF']."?page=".$pagecount."&page_type=".$anothersearchstr."&parameter2=".$anothersearchstrs." class=".$class.">尾页</a>";117         else118             $str.="<font color='#555555'>尾页</font>";119         if(count($this->array)==0 || $this->array==false)            120             return "无数据。";121         else122             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 ?>

 

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索模块 参考 ,以便于您获取更多的相关知识。