<?php

/**
 * 版权所有，盗版必查水表
 */

/**
 * 竞投关注表
 *
 * @author Administrator
 */
class GrowthBidAttention {
    /**
     *
     * @var TINY_ADODB 主数据库
     */
    private $db;
    /**
     *
     * @var TINY_ADODB 从数据库
     */
    private $dbback;
    /**
     *
     * @var Memcache 缓存
     */
    private $mc;
    /**
     *
     * @var string 表名
     */
    private $table;
    /**
     *
     * @var 表中字段数组 
     */
    private $fields;
    
    /**
     * 初始化类
     * @param string $table 表名，默认为growth_bid_periods
     */
    public function __construct($table = 'growth_bid_attention') {
        $container = Container::getInstance();
        $this->db = $container->get('db');
        $this->dbback = $container->get('dbback');
        $this->table = $table;
        $this->mc = $container->get('mc');
        $sqlfield = "DESC $this->table";
        $fieldsMKey = $sqlfield;
        $this->fields = $this->mc->get($fieldsMKey);
        if($this->fields === false) {
            $fields = $this->dbback->getAll($sqlfield);
            foreach ($fields as $field) {
                $this->fields[] = $field['Field'];
            }
            $this->mc->set($fieldsMKey, $this->fields, 3600);
        }
    }
    
    public function findById($id) {
        $sql = SqlCombinHelper::select_sql($this->table, $this->fields,"id='$id'");
        return $this->dbback->GetRow($sql);
    }
    //xue modify db->dbback 2015-05-04
    public function findBy($conf) {
       $sql = SqlCombinHelper::select_sql($this->table, $this->fields,$conf);
        return $this->dbback->GetAll($sql);
    }
    
    public function findNumberBy($conf) {
        $sql = SqlCombinHelper::count_sql($this->table, $conf);
        return $this->dbback->getOne($sql);
    }

    public function update($fieldData,$conf) {
        $sql = SqlCombinHelper::update_sql($this->table, $fieldData, $conf);
        $this->db->Execute($sql);
        return $this->db->Affected_Rows();
    }

    public function insert($fieldData) {
        $sql = SqlCombinHelper::insert_sql($this->table, $fieldData);
        $this->db->Execute($sql);
        return $this->db->Insert_ID();
    }
    
    public function delBy($conf) {
        $sql = SqlCombinHelper::delete_sql($this->table, $conf);
        $this->db->Execute($sql);
        return $this->db->Affected_Rows();
    }
    
}

?>
