当前位置:编程学习 > php >>

php试用smarty和ADODB实现对数据分页读取

<?php 
define('BASE_PATH',$_SERVER['DOCUMENT_ROOT']); 
define('SMARTY_PATH','\smartTest\Smarty\\'); 
require BASE_PATH.SMARTY_PATH.'Smarty.class.php'; 
/*$dir2的这种路径显示到表现页是这下面字符串是一样,导致smarty找不到templates路径*/ 
//$dir2 = "../Smarty/tempplates/"; 
class SmartyProject extends Smarty{ 
     
    function SmartyProject(){ 
        /*必须加这个parent::__construct();,否则,Smarty不会被构造,truncate等不能用,
         * 但这似乎没有道理,但事实上,
         * 这么做确实解决了truncate不能使用的问题*/ 
        parent::__construct(); 
        $this->template_dir = BASE_PATH.SMARTY_PATH.'/templates/'; 
        $this->compile_dir = BASE_PATH.SMARTY_PATH.'/templates_c/'; 
        $this->config_dir = BASE_PATH.SMARTY_PATH.'/configs/'; 
        $this->cache_dir = BASE_PATH.SMARTY_PATH.'/cache/'; 
    } 

 
class ConnDB{ 
    var $dbtype; 
    var $host; 
    var $user; 
    var $pwd; 
    var $dbname; 
    var $debug; 
    var $conn; 
    function ConnDB($dbtype, $host, $user, $pwd, $dbname, $debug=FALSE){//构造函数 
        $this->dbtype=$dbtype; 
        $this->host=$host; 
        $this->user=$user; 
        $this->pwd=$pwd; 
        $this->dbname=$dbname; 
        $this->debug=$debug;  
    } 
    function GetConnId(){ 
        require BASE_PATH.'/smartTest/adodb5/adodb.inc.php';//将adodb的主文件引用进来 
        if($this->dbtype == 'mysql'){ 
            $this->conn = NewADOConnection('mysql'); 
            $this->conn->Connect($this->host, $this->user, $this->pwd, $this->dbname); 
        }else if($this->dbtype == 'mssql'){ 
            $this->conn = NewADOConnection('mssql'); 
            $this->conn->Connect($this->host, $this->user, $this->pwd, $this->dbname); 
        }else if($this->dbtype == 'access'){ 
            $this->conn = NewADOConnection('access'); 
            $this->conn->Connect("Driver={Microsoft Access Driver(*.mdb)};Dbq=".$this->dbname.";Uid=".$this->user.";Pwd=".$this->pwd.";"); 
        } 
        $this->conn->Execute("set names utf-8"); 
        if($this->dbtype == 'mysql') 
            $this->conn->debug = $this->debug; 
        return $this->conn; 
    } 
    function CloseConnId(){ 
        $this->conn->Disconnect(); 
    } 

 
class AdminDB{ 
    function ExecSQL($sqlstr, $conn){ 
        $sqltype = strtolower(substr(trim($sqlstr), 0,6));//去sql语句的前6个字符 
        $rs = $conn->Execute($sqlstr); 
        if($sqltype == 'select'){ 
            $array = $rs->GetRows(); 
            if(count($array)==0 || $rs == false) 
                return false; 
            else  
                return $array; 
        }else if($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; 
        //执行查询语句 
        $this->rs = $this->conn->PageExecute($this->sqlstr,$this->pagesize,$this->nowpage);//调用ADODO类中的这个方法 
        @$this->array = $this->rs->GetRows(); 
        if(count($this->array)==0||$this->rs == false) 
            return  false; 
     

补充:Web开发 , php ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,