php模块参考,php

原创
2016-06-13 09:29:49 646浏览

php模块参考,php

  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() . "
"); 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.="$anothersearchstr
."&parameter2=".$anothersearchstrs." class=".$class.">首页"; 102 else 103 $str.="首页"; 104 $str.=" "; 105 if($this->nowpage!=1) 106 $str.="$this->nowpage-1)."&page_type=".$anothersearchstr."&parameter2=".$anothersearchstrs." class=".$class.">上一页"; 107 else 108 $str.="上一页"; 109 $str.=" "; 110 if($this->nowpage!=$pagecount) 111 $str.="$this->nowpage+1)."&page_type=".$anothersearchstr."&parameter2=".$anothersearchstrs." class=".$class.">下一页"; 112 else 113 $str.="下一页"; 114 $str.=" "; 115 if($this->nowpage!=$pagecount) 116 $str.="$pagecount."&page_type=".$anothersearchstr."&parameter2=".$anothersearchstrs." class=".$class.">尾页"; 117 else 118 $str.="尾页"; 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]","",$content); 131 $content=str_replace("[/strong]","",$content); 132 $content=str_replace("[em]","",$content); 133 $content=str_replace("[/em]","",$content); 134 $content=str_replace("[u]","",$content); 135 $content=str_replace("[/u]","",$content); 136 137 138 $content=str_replace("[font color=#FF0000]","",$content); 139 $content=str_replace("[font color=#00FF00]","",$content); 140 $content=str_replace("[font color=#0000FF]","",$content); 141 142 $content=str_replace("[font face=楷体_GB2312]","",$content); 143 $content=str_replace("[font face=宋体]","",$content); 144 $content=str_replace("[font face=隶书]","",$content); 145 $content=str_replace("[/font]","",$content); 146 //$content=str_replace(chr(32)," ",$content); 147 $content=str_replace("[font size=1]","",$content); 148 $content=str_replace("[font size=2]","",$content); 149 $content=str_replace("[font size=3]","",$content); 150 $content=str_replace("[font size=4]","",$content); 151 $content=str_replace("[font size=5]","",$content); 152 $content=str_replace("[font size=6]","",$content); 153 154 $content=str_replace("[FIELDSET][LEGEND]","
",$content); 155 $content=str_replace("[/LEGEND]","",$content); 156 $content=str_replace("[/FIELDSET]","
",$content); 157 return $content; 158 } 159 160 } 161 162 ?>

问php有什比较流行的模块?

说模块....我太理解,因php模块php环境概念,php环境由多模块组成,模块用来php实现某些功能,比说gd库,用来实现图片操作.

过我觉得说代码块,或者指重用代码,找php类去www.phpclasses.org,官方有2项目,叫PEAR,另外叫PECL,里面提供了大量功能支持,还有兄弟已经入门了,我建议看看zendframework.

已经有的php模块怎使用?是添加到网页?

留言板源码复制web目录下比bbs目录主页面加链接bbs目录下留言程序行
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。