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 ...
随机推荐
- nyoj 1036 非洲小孩【贪心区间选点】
非洲小孩 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 家住非洲的小孩,都很黑.为什么呢?第一,他们地处热带,太阳辐射严重.第二,他们不经常洗澡.(常年缺水,怎么洗 ...
- Day 3 @ RSA Conference Asia Pacific & Japan 2016 (morning)
09.00 – 09.45 hrs Tracks Cloud, Mobile, & IoT Security A New Security Paradigm for IoT (Inter ...
- Javascript——初步
1.基本概念 Javascript是一门脚本语言,它是一门解释性的语言.网页和用户之间实时.动态的进行交互. 2.特点 简单性:没有严格的数据类型.语句简单而紧凑. 安全性:仅仅能通过浏览器实现浏览和 ...
- Android NDK 【错误】The method loadLibrary(String) is undefined for the type Settings.Syste
[错误]The method loadLibrary(String) is undefined for the type Settings.System [解决方法] 不要加入包import andr ...
- a href=#与 a href=javascript:void(0) 的差别
a href="#"> 点击链接后,页面会向上滚到页首,# 默认锚点为 #TOP <a href="javascript:void(0)" onCl ...
- iOS常见的几种延时执行的方法
1.performSelector [self performSelector:@selector(delayMethod) withObject:nil/*可传任意类型参数*/ afterDelay ...
- Unity3D中读取CSV文件
直接上代码 Part1: using UnityEngine; using System.IO; using System.Collections.Generic; public class CSV ...
- dedeCMS修改文章更新发布时间问题
今天在dedeCMS系统中,修改或文章时发现,只要提交以后,文章发布时间便是当前时间.但有时候修改文章以后并不想把文章发布时间也更新成修改时间.我希望的是,修改文章不对时间做更改保持文章原有发布时间, ...
- js - 在拼接字符串中动态submit当前form
今天在做一个项目的时候, mapabc中的inforWindow中,如果是超链接a,不直接响应. 后来的解决方案是动态产生form,并调用summit方法.如下 自定义一个js函数: function ...
- union与union all 的区别
Union与Union All的区别 如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或称为联合)的作用是将多个结果合并 ...