记录我的一些生活写照、无聊的牢骚、内心世界的活动 注册 | 登陆

一个基于php5的简单的数据库处理模型

    对于编成方面,自己确实是弱的很,但却不能因为这个而剥夺了我喜欢的权利。PHP5出了也有一段时间了,早就听说在OO方便增强了很多,试了一下还真的是不错的。但自己对OO却知之甚少,只粗略的知道了一点皮毛而已。下载这个是我自己在用的一个见得数据处理模型,因为本来就知道的不错,所以也就尽可能的简单了,希望大家斧正!

 

    这里是一个简单的应用,只是来给大家演示一下是如何应用的,至于文档嘛,本来做得就不好,而且也懒得写了,还是看看实例来的方便些!

<?php
//
// +----------------------------------------------------------------------+
// | PHP version 5.0                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004                                                   |
// | Moocky Mark(木目子).                                                  |
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Authors:    Moocky Mark                                              |
// | QQ:         44333697                                                 |
// | MSN:        moocky@hotmail.com                                       |
// | Email:      moocky@moocky.net                                        |
// +----------------------------------------------------------------------+
//
//

/**
* 使用方法范例
*
*
* @version  v 1.0
* @access   Note
*/

class TestData extends abstractData{
    
private $sTable    ='TestData';
    
public function __construct(&$conn)
    {
        
$this->_oConn    = $conn;
    }

   
/**
    * 增加记录
    * @params $maInfo:Array;
    * @return Int;
    */
    
public function add($maInfo)
    {
        
$maInfo["intime"]=date('Y-m-d H:i:s');

        
$iID = $this->insert($this->sTable, $maInfo);
        if(
$iID)
        {
            return
$iID;
        }
            return
0;
    }

   
/**
    * 更新记录
    * @params $maInfo:Array;
    * @params $miID:Int;
    * @return Boolean;
    */
    
public function modify($maInfo, $miID)
    {
        if(
$this->update($this->sTable, $maInfo, $where))
        {
            return
true;
        }
            return
false;
    }

   
/**
    * 得到记录内容
    * @params Int;
    * @return Array;
    */
    
public function get($miID)
    {
        
$sSQL = sprintf("select `topic`,`content`,`intime`,`hits` from `%s` where `note_id`='%s'",
                        
$this->sTable,$miID);
        
$this->_oConn->executeQuery();
        while(
$this->_oConn->next())
        {
            
$D["topic"]        =$this->_oConn->getString("topic");
            
$D["content"]    =$this->_oConn->getString("content");
            
$D["intime"]    =$this->_oConn->getString("intime");
        }
        return
$D;
    }

   
/**
    * 统计公告
    * @params $Where    :String;
    * @return Int;
    */
    
public function getCount($mWhere="")
    {
        if(
is_array($mWhere)){
            
$where = "where ".$this->getWhere($mWhere);
        }elseif(
$mWhere!=""){
            
$where = "where ".$mWhere;
        }
        
$sSQL = sprintf("select count(1) as `total` from `%s` %s",
                
$this->sTable,$where);
        
$this->_oConn->executeQuery($sSQL);
        if(
$this->_oConn->next())
        {
            return
$this->_oConn->getString("total");
        }
        return
0;
    }

   
/**
    * 列出公告
    * @params $Where:    String;
    * @params $Order:        String;
    * @params $Limit:        Int;
    * @params $RowCount:    Int;
    * @return Array;
    */
    
public function getList($mWhere="",$Order="",$Limit=0,$RowCount=20)
    {
        if(
is_array($mWhere)){
            
$where = "where ".$this->getWhere($mWhere);
        }elseif(
$mWhere!=""){
            
$where = "where ".$mWhere;
        }
        if(
$Order=="")
        {
            
$Order="`intime` desc";
        }
        
$sSQL=sprintf("select `id`,`topic`,`intime` from `%s` %s order by %s limit %s,%s",
                    $
$this->sTable,
                    
$where,
                    
$Order,
                    
$Limit,
                    
$RowCount);
        
$this->_oConn->executeQuery($sSQL);
        
$i = 0;
        while(
$this->_oConn->next())
        {
            
$D[$i]["note_id"]    =$this->_oConn->getString("note_id");
            
$D[$i]["topic"]        =$this->_oConn->getString("topic");
            
$D[$i]["intime"]    =$this->_oConn->getString("intime");
            
$i++;
        }
        return
$D;
    }
   
/**
    * 删除文章
    * @params Int;
    * @return Int;
    */
    
public function delete($miID)
    {
        return
$this->del($this->sTable,"`id`='$miID'");
    }

}
?>

附件: abstractdata.class.rar (1.82 K, 下载次数:6)

Tags: php

« 上一篇 | 下一篇 »

只显示10条记录相关文章

PHP5.2.0正式发布 (浏览: 5069, 评论: 0)
PHP的扩展和嵌入---一本不错的书 (浏览: 42895, 评论: 0)
微软淘汰甲骨文 以1.13亿美元控股Zend (浏览: 5887, 评论: 0)
有关PHP4和PHP5不兼容的问题 (浏览: 36821, 评论: 3)
PHP6即将出炉了,看看都有什么新东西! (浏览: 2859, 评论: 0)
Minutes PHP Developers Meeting (浏览: 2885, 评论: 0)
PHP5.1终于又出来了 (浏览: 3670, 评论: 0)
截取中英文混排字符串的函数 (浏览: 3240, 评论: 0)
Windows下的Apache+MySQL+PHP运行环境的搭建基础篇 (浏览: 4389, 评论: 1)
PHP5之__set和__get (浏览: 2752, 评论: 0)

Trackbacks

点击获得Trackback地址,Encode: UTF-8 点击获得Trackback地址,Encode: GB2312 or GBK 点击获得Trackback地址,Encode: BIG5

发表评论

评论内容 (必填):