php模块参考
<?php
//数据库连接类
class ConnDB{ var $dbtype;
var $host;
var $user;
var $pwd;
var $dbname; //构造方法
function ConnDB($dbtype,$host,$user,$pwd,$dbname){
$this->dbtype=$dbtype;
$this->host=$host;
$this->user=$user;
$this->pwd=$pwd;
$this->dbname=$dbname;
} //实现数据库的连接并返回连接对象
function GetConnId(){ if($this->dbtype=="mysql" || $this->dbtype=="mssql"){
$dsn="$this->dbtype:host=$this->host;dbname=$this->dbname";
}else{
$dsn="$this->dbtype:dbname=$this->dbname";
}
try {
$conn = new PDO($dsn, $this->user, $this->pwd); //初始化一个PDO对象,就是创建了数据库连接对象$pdo
$conn->query("set names utf8");
return $conn;
} catch (PDOException $e) {
die ("Error!: " . $e->getMessage() . "<br/>");
} }
} //数据库管理类
class AdminDB{ function ExecSQL($sqlstr,$conn){ $sqltype=strtolower(substr(trim($sqlstr),0,6));
$rs=$conn->prepare($sqlstr); //准备查询语句
$rs->execute(); //执行查询语句,并返回结果集
if($sqltype=="select"){
$array=$rs->fetchAll(PDO::FETCH_ASSOC); //获取结果集中的所有数据
if(count($array)==0 || $rs==false)
return false;
else
return $array;
}elseif ($sqltype=="update" || $sqltype=="insert" || $sqltype=="delete"){
if($rs)
return true;
else
return false;
}
}
}
//分页类
class SepPage{
var $rs;
var $pagesize;
var $nowpage;
var $array;
var $conn;
var $sqlstr;
function ShowData($sqlstr,$conn,$pagesize,$nowpage){ //定义方法
if(!isset($nowpage) || $nowpage=="") //判断变量值是否为空
$this->nowpage=1; //定义每页起始页
else
$this->nowpage=$nowpage;
$this->pagesize=$pagesize; //定义每页输出的记录数
$this->conn=$conn; //连接数据库返回的标识
$this->sqlstr=$sqlstr; //执行的查询语句
$offset=($this->nowpage-1)*$this->pagesize;
$sql=$this->sqlstr." limit $offset, $this->pagesize";
$result=$this->conn->prepare($sql); //准备查询语句
$result->execute(); //执行查询语句,并返回结果集
$this->array=$result->fetchAll(PDO::FETCH_ASSOC); //获取结果集中的所有数据
if(count($this->array)==0 || $this->array==false)
return false;
else
return $this->array;
} function ShowPage($contentname,$utits,$anothersearchstr,$anothersearchstrs,$class){
$str="";
$res=$this->conn->prepare($this->sqlstr); //准备查询语句
$res->execute(); //执行查询语句,并返回结果集
$this->array=$res->fetchAll(PDO::FETCH_ASSOC); //获取结果集中的所有数据
$record=count($this->array); //统计记录总数 $pagecount=ceil($record/$this->pagesize); //计算共有几页
$str.=$contentname." ".$record." ".$utits." 每页 ".$this->pagesize." ".$utits." 第 ".$this->nowpage." 页/共 ".$pagecount." 页";
$str.=" ";
if($this->nowpage!=1)
$str.="<a href=".$_SERVER['PHP_SELF']."?page=1&page_type=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">首页</a>";
else
$str.="<font color='#555555'>首页</font>";
$str.=" ";
if($this->nowpage!=1)
$str.="<a href=".$_SERVER['PHP_SELF']."?page=".($this->nowpage-1)."&page_type=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">上一页</a>";
else
$str.="<font color='#555555'>上一页</font>";
$str.=" ";
if($this->nowpage!=$pagecount)
$str.="<a href=".$_SERVER['PHP_SELF']."?page=".($this->nowpage+1)."&page_type=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">下一页</a>";
else
$str.="<font color='#555555'>下一页</font>";
$str.=" ";
if($this->nowpage!=$pagecount)
$str.="<a href=".$_SERVER['PHP_SELF']."?page=".$pagecount."&page_type=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">尾页</a>";
else
$str.="<font color='#555555'>尾页</font>";
if(count($this->array)==0 || $this->array==false)
return "无数据!";
else
return $str;
}
}
//系统常用方法
class UseFun{ function UnHtml($text){
$content=(nl2br(htmlspecialchars($text)));
$content=str_replace("[strong]","<strong>",$content);
$content=str_replace("[/strong]","</strong>",$content);
$content=str_replace("[em]","<em>",$content);
$content=str_replace("[/em]","</em>",$content);
$content=str_replace("[u]","<u>",$content);
$content=str_replace("[/u]","</u>",$content); $content=str_replace("[font color=#FF0000]","<font color=#FF0000>",$content);
$content=str_replace("[font color=#00FF00]","<font color=#00FF00>",$content);
$content=str_replace("[font color=#0000FF]","<font color=#0000FF>",$content); $content=str_replace("[font face=楷体_GB2312]","<font face=楷体_GB2312>",$content);
$content=str_replace("[font face=宋体]","<font face=新宋体>",$content);
$content=str_replace("[font face=隶书]","<font face=隶书>",$content);
$content=str_replace("[/font]","</font>",$content);
//$content=str_replace(chr(32)," ",$content);
$content=str_replace("[font size=1]","<font size=1>",$content);
$content=str_replace("[font size=2]","<font size=2>",$content);
$content=str_replace("[font size=3]","<font size=3>",$content);
$content=str_replace("[font size=4]","<font size=4>",$content);
$content=str_replace("[font size=5]","<font size=5>",$content);
$content=str_replace("[font size=6]","<font size=6>",$content); $content=str_replace("[FIELDSET][LEGEND]","<FIELDSET><LEGEND>",$content);
$content=str_replace("[/LEGEND]","</LEGEND>",$content);
$content=str_replace("[/FIELDSET]","</FIELDSET>",$content);
return $content;
} } ?>
php模块参考的更多相关文章
- Nginx模块参考手册:HTTP核心模块
FROM: http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=17238776&id=2982697 这些模块默认会全部编 ...
- 函数的学习3——传递任意数量的实参&将函数存储在模块——参考Python编程从入门到实践
传递任意数量的实参 形参前加一个 * ,Python会创建一个已形参为名的空元组,将所有收到的值都放到这个元组中: def make_pizza(*toppings): print("\nM ...
- [转载]python中的sys模块(二)
#!/usr/bin/python # Filename: using_sys.py import sys print 'The command line arguments are:' for i ...
- NodeJs + mongodb模块demo
代码比较通俗易懂,但是我还是在这个过程中浪费了不少时间,也算是看到了nodejs中异步的一个小坑.未来的坑还有很多,慢慢找坑填坑吧. 参考资料如下: 1.断言模块 : https://nodejs.o ...
- python3+ 模块学习 之 re
re 模块 参考:Python3 如何优雅地使用正则表达式(详解系列) Python3 正则表达式特殊符号及用法(详细列表) (出处: 鱼C论坛) 正则表达式 常用元字符:. ^ $ * + ? ...
- OFBiz进阶之HelloWorld(一)创建热部署模块
创建热部署模块 参考文档 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Developm ...
- 读Zepto源码之Callbacks模块
Callbacks 模块并不是必备的模块,其作用是管理回调函数,为 Defferred 模块提供支持,Defferred 模块又为 Ajax 模块的 promise 风格提供支持,接下来很快就会分析到 ...
- 读Zepto源码之Deferred模块
Deferred 模块也不是必备的模块,但是 ajax 模块中,要用到 promise 风格,必需引入 Deferred 模块.Deferred 也用到了上一篇文章<读Zepto源码之Callb ...
- 读Zepto源码之Ajax模块
Ajax 模块也是经常会用到的模块,Ajax 模块中包含了 jsonp 的现实,和 XMLHttpRequest 的封装. 读 Zepto 源码系列文章已经放到了github上,欢迎star: rea ...
随机推荐
- javascript排序 查找算法大全
在pptv的实习结束了, 忙着找工作的事,顺便把数据结构的那本书重新复习了一遍.为了加深印象,特意把里面的常用的排序.查找算法用js写了一遍 具体的实例在我的github上,大家可以访问的: http ...
- BOM、DOM学习笔记——JavaScript
1.BOM的概述 browser object modal :浏览器对象模型. 浏览器对象:window对象. Window 对象会在 <body> 或 <fram ...
- 01 Access数据库 测试连接
附件:http://files.cnblogs.com/xe2011/AccesssConnectionState.rar using System.Data.OleDb; using System. ...
- Android中利用OpenMax 编程的基本流程
近期因为公司在做数字电视,播放器和模块由供应商打包一起卖,驱动调通了,但是播放器要硬件解码,和平台差异,原厂又没有相关文档,就自己试着看了一个系统的播放器流程,顺便整理了一下,也方便以后查询,希望对播 ...
- 用nginx图片缓存服务器
图片的存储硬件 把图片存储到什么介质上? 如果有足够的资金购买专用的图片服务器硬件或者 NAS 设备,那么简单的很: 如果上述条件不具备,只想在普通的硬盘上存储,首先还是要考虑一下物理硬盘的实际处理能 ...
- hadoop错误org.apache.hadoop.util.DiskChecker$DiskErrorException Could not find any valid local directory for
错误: org.apache.hadoop.util.DiskChecker$DiskErrorException: Could not find any valid local directory ...
- CI框架篇之模型篇--初识(1)
模型 模型是专门用来和数据库打交道的PHP类.例如,假设你想用CodeIgniter来做一个Blog. 你可以写一个模型类,里面包含插入.更新.删除Blog数据的方法. 下面的例子将向你展示一个普通的 ...
- EnumWindows 使用
转载自csdn:http://blog.csdn.net/hairi/article/details/548064 EnumWindows 用来列举屏幕上所有顶层窗口. MSDN原话: The E ...
- 第一节 WCF概述
主要内容: 1.什么是WCF? 2.WCF的背景介绍. 引例:(WCF用来解决什么事情) 一家汽车租赁公司决定创建一个新的应用程序,用于汽车预定 • 该租车预定应用程序的创建者知道,应用程序所实现的业 ...
- windows 8 vpn 错误解决
最近微软发布了Windows 8 RTM版,很多朋友也安装了,我当然也不例外.这几天就有不少朋友问我VPN连接无论怎么都说密码错误不能验证,于是,便连接VPN进行了下测试,如下: 配置好VPN,步凑不 ...