php中的数据库操作类、分页类,以及smarty扩展类
2016-12-01 10:40
267 查看
相关链接
smarty扩展类
<?php
$file=dirname(dirname(str_replace("\\","/",__FILE__)));
require $file."/smarty/Smarty.class.php";
class smartyProject extends smarty
{
function __construct()
{
parent::__construct();//基类的构造函数不能少
$this->template_dir=dirname(dirname(str_replace("\\","/",__FILE__)))."/smarty/templates";
$this->compile_dir=dirname(dirname(str_replace("\\","/",__FILE__)))."/smarty/templates_c";
$this->config_dir=dirname(dirname(str_replace("\\","/",__FILE__)))."/smarty/configs";
$this->cache_dir=dirname(dirname(str_replace("\\","/",__FILE__)))."/smarty/cache";
}
}
?>
数据库操作类、分页类
<style>
.link1
{
text-decoration:none;
}
</style>
<?php
class OperateDb
{
public $dbms='mysql';
public $host='localhost';
public $dbname='db_business';
public $user='root';
public $pwd='root';
public $pdo="";
public $sql="";
function __construct($dbms='mysql',$host='localhost',$dbname='db_business',$user='root',$pwd='root')
{
$this->dbms=$dbms;
$this->host=$host;
$this->dbname=$dbname;
$this->user=$user;
$this->pwd=$pwd;
$dsn="$dbms:host=$host;dbname=$dbname";
$this->pdo=new PDO($dsn,$user,$pwd);
$this->pdo->exec("set names utf8");
return $this->pdo;
}
function handleSql($sql)
{
$this->sql=$sql;
$subsql=substr($sql,0,5);
//插入、删除、更新
if($substr=='insert'||$substr=='update'||$substr=='delete')
{
if($this->pdo->exec($this->sql))
{
return "操作成功!";
}
}
else if($subsql='select')
{
echo $this->sql;
$result=$this->pdo->prepare($this->sql);
$result->execute();
if(!$result)
{
echo "数据查询失败!";
}
else
{
$arrarr=$result->fetchall();
return $arrarr;
}
}
}
}
class SepPage
{
public $ceilcount="";
public $pagecount="";
public $nowpage="";
public $pagesize="";
//public $offset;
function showdata($sql,$pdo,$pagesize,$page)
{
$this->pagesize=$pagesize;
if($page=="")
{
$page=1;
}
$this->nowpage=$page;
$offset=($page-1)*$pagesize;
$arrarr0=$pdo->handlesql($sql);
$arrarr=$pdo->handlesql($sql." limit $offset,$pagesize");
$this->ceilcount=count($arrarr0);
$this->pagecount=ceil($this->ceilcount/$this->pagesize);
return $arrarr;
}
function showpage($name,$unit)
{
$str="共有$name ".$this->ceilcount." $unit ";
$str.="每页显示".$this->pagesize.$unit;
$str.=" 第".$this->nowpage."页/共".$this->pagecount."页";
$str.=" <a class='link1' href='".$_SERVER['PHP_SELF']."?page=1'>首页</a>";
//上一页 要分nowpage大于1或等于1的情况
if($this->nowpage>1)
{
$str.="<a class='link1' href='".$_SERVER['PHP_SELF']."?page=".($this->nowpage-1)."'>上一页</a>";
}
else if($this->nowpage=1)
{
$str.="<a class='link1' href='".$_SERVER['PHP_SELF']."?page=1'>上一页</a>";
}
//下一页 要分nowpage小于pagecount或等于pagecount的情况
if($this->nowpage<$this->pagecount)
{
$str.="<a class='link1' href='".$_SERVER['PHP_SELF']."?page=".($this->nowpage+1)."'>下一页</a>";
}
else if($this->nowpage=$this->pagecount)
{
$str.="<a class='link1' href='".$_SERVER['PHP_SELF']."?page=".($this->pagecount)."'>下一页</a>";
}
$str.="<a class='link1' href='".$_SERVER['PHP_SELF']."?page=".($this->pagecount)."'>末页</a>";
return $str;
}
}
?>
smarty扩展类
<?php
$file=dirname(dirname(str_replace("\\","/",__FILE__)));
require $file."/smarty/Smarty.class.php";
class smartyProject extends smarty
{
function __construct()
{
parent::__construct();//基类的构造函数不能少
$this->template_dir=dirname(dirname(str_replace("\\","/",__FILE__)))."/smarty/templates";
$this->compile_dir=dirname(dirname(str_replace("\\","/",__FILE__)))."/smarty/templates_c";
$this->config_dir=dirname(dirname(str_replace("\\","/",__FILE__)))."/smarty/configs";
$this->cache_dir=dirname(dirname(str_replace("\\","/",__FILE__)))."/smarty/cache";
}
}
?>
数据库操作类、分页类
<style>
.link1
{
text-decoration:none;
}
</style>
<?php
class OperateDb
{
public $dbms='mysql';
public $host='localhost';
public $dbname='db_business';
public $user='root';
public $pwd='root';
public $pdo="";
public $sql="";
function __construct($dbms='mysql',$host='localhost',$dbname='db_business',$user='root',$pwd='root')
{
$this->dbms=$dbms;
$this->host=$host;
$this->dbname=$dbname;
$this->user=$user;
$this->pwd=$pwd;
$dsn="$dbms:host=$host;dbname=$dbname";
$this->pdo=new PDO($dsn,$user,$pwd);
$this->pdo->exec("set names utf8");
return $this->pdo;
}
function handleSql($sql)
{
$this->sql=$sql;
$subsql=substr($sql,0,5);
//插入、删除、更新
if($substr=='insert'||$substr=='update'||$substr=='delete')
{
if($this->pdo->exec($this->sql))
{
return "操作成功!";
}
}
else if($subsql='select')
{
echo $this->sql;
$result=$this->pdo->prepare($this->sql);
$result->execute();
if(!$result)
{
echo "数据查询失败!";
}
else
{
$arrarr=$result->fetchall();
return $arrarr;
}
}
}
}
class SepPage
{
public $ceilcount="";
public $pagecount="";
public $nowpage="";
public $pagesize="";
//public $offset;
function showdata($sql,$pdo,$pagesize,$page)
{
$this->pagesize=$pagesize;
if($page=="")
{
$page=1;
}
$this->nowpage=$page;
$offset=($page-1)*$pagesize;
$arrarr0=$pdo->handlesql($sql);
$arrarr=$pdo->handlesql($sql." limit $offset,$pagesize");
$this->ceilcount=count($arrarr0);
$this->pagecount=ceil($this->ceilcount/$this->pagesize);
return $arrarr;
}
function showpage($name,$unit)
{
$str="共有$name ".$this->ceilcount." $unit ";
$str.="每页显示".$this->pagesize.$unit;
$str.=" 第".$this->nowpage."页/共".$this->pagecount."页";
$str.=" <a class='link1' href='".$_SERVER['PHP_SELF']."?page=1'>首页</a>";
//上一页 要分nowpage大于1或等于1的情况
if($this->nowpage>1)
{
$str.="<a class='link1' href='".$_SERVER['PHP_SELF']."?page=".($this->nowpage-1)."'>上一页</a>";
}
else if($this->nowpage=1)
{
$str.="<a class='link1' href='".$_SERVER['PHP_SELF']."?page=1'>上一页</a>";
}
//下一页 要分nowpage小于pagecount或等于pagecount的情况
if($this->nowpage<$this->pagecount)
{
$str.="<a class='link1' href='".$_SERVER['PHP_SELF']."?page=".($this->nowpage+1)."'>下一页</a>";
}
else if($this->nowpage=$this->pagecount)
{
$str.="<a class='link1' href='".$_SERVER['PHP_SELF']."?page=".($this->pagecount)."'>下一页</a>";
}
$str.="<a class='link1' href='".$_SERVER['PHP_SELF']."?page=".($this->pagecount)."'>末页</a>";
return $str;
}
}
?>
相关文章推荐
- php书写的通用数据库操作类(便于扩展)
- phpfans留言版用到的数据操作类和分页类
- php数据库操作类---mysql
- 安装php的tokyo_tyrant扩展时遇到的问题,以及解决方法
- PHP 显示页面以及数据库中出现乱码问题的解决方式
- UCHome中数据库操作类(class_mysql.php)页面的代码分析
- 数据库操作类(PHP/mysql)
- php 数据库操作类
- php 数据库操作类
- php的smarty的foreach以及section循环方法!
- php数据库操作类---mysql
- php odbc 数据库操作类
- php odbc 数据库操作类
- php 数据库操作类
- PHP扩展模块Pecl、Pear以及Perl的区别
- php 一个分页类和一个数据库的类
- PHP建立数据库以及表格
- php分页类扩展
- PHP扩展pcntl(进程控制以及信号处理)中文文档
- PHP数据库操作类