报错以下内容
对应的文件内容<?php
//Model基类
class Model extends DB {
protected $_db = null;
protected $_fields = array();
protected $_tables = array();
protected $_R = array();
protected $_check = null;
protected $_limit = '';

protected function __construct() {
$this->_db = parent::getInstance();
}

protected function add(Array $_addData) {
return $this->_db->add($this->_tables, $_addData);
}

protected function update(Array $_param, Array $_updateData) {
return $this->_db->update($this->_tables, $_param, $_updateData);
}

protected function select(Array $_field, Array $_param = array()) {
return $this->_db->select($this->_tables, $_field, $_param);
}

protected function total(Array $_param = array()) {
return $this->_db->total($this->_tables, $_param);
}

protected function nextId() {
return $this->_db->nextId($this->_tables);
}

protected function getRequest() {
return Request::getInstance($this, $this->_check);
}

protected function delete(Array $_param) {
return $this->_db->delete($this->_tables, $_param);
}

public function isOne(Array $_param) {
return $this->_db->isOne($this->_tables, $_param);
}

public function setLimit($_limit) {
$this->_limit = $_limit;
}
}
?>

解决方案 »

  1.   

    <?php
    //管理员实体类
    class ManageModel extends Model {
    public function __construct() {
    parent::__construct();
    $this->_fields = array('id','user','pass','level','login_count','last_ip','last_time','reg_time');
    $this->_tables = array(DB_FREFIX.'manage');
    $this->_check = new ManageCheck();
    list(
    $this->_R['id'], 
    $this->_R['user'], 
    $this->_R['pass'], 
    $this->_R['code']
    ) = $this->getRequest()->getParam(array(
    isset($_GET['id']) ? $_GET['id'] : null,
    isset($_POST['user']) ? $_POST['user'] : null,
    isset($_POST['pass']) ? $_POST['pass'] : null,
    isset($_POST['code']) ? $_POST['code'] : null
    ));
    }

    public function findAll() {
    $this->_tables = array(DB_FREFIX.'manage a', DB_FREFIX.'level b');
    return parent::select(array('a.id','a.user','a.level','a.login_count','a.last_ip','a.last_time', 'b.level_name'), 
    array('where'=>array('a.level=b.id'),'limit'=>$this->_limit, 'order'=>'a.reg_time DESC'));
    }

    public function findOne() {
    $_where = array("id='{$this->_R['id']}'");
    if (!$this->_check->oneCheck($this, $_where)) $this->_check->error();
    return parent::select(array('id','user','level'),
    array('where'=>$_where, 'limit'=>'1'));
    }

    public function findLogin() {
    $this->_tables = array(DB_FREFIX.'manage a', DB_FREFIX.'level b');
    return parent::select(array('a.user', 'b.level_name'),
    array('where'=>array('a.level=b.id', "user='{$this->_R['user']}'"), 'limit'=>'1'));
    }

    public function countLogin() {
    $_where = array("user='{$this->_R['user']}'");
    $_updateData['login_count'] = array('login_count+1');
    $_updateData['last_ip'] = Tool::getIP();
    $_updateData['last_time'] = Tool::getDate();
    parent::update($_where, $_updateData);
    }

    public function total() {
    return parent::total();
    }

    public function add() {
    $_where = array("user='{$this->_R['user']}'");
    if (!$this->_check->addCheck($this, $_where)) $this->_check->error();
    $_addData = $this->getRequest()->add($this->_fields);
    $_addData['pass'] = sha1($_addData['pass']);
    $_addData['last_ip'] = Tool::getIP();
    $_addData['reg_time'] = Tool::getDate();
    return parent::add($_addData);
    }

    public function update() {
    $_where = array("id='{$this->_R['id']}'");
    if (!$this->_check->oneCheck($this, $_where)) $this->_check->error();
    if (!$this->_check->updateCheck($this)) $this->_check->error();
    $_updateData = $this->getRequest()->update($this->_fields);
    $_updateData['pass'] = sha1($_updateData['pass']);
    return parent::update($_where, $_updateData);
    }

    public function delete() {
    $_where = array("id='{$this->_R['id']}'");
    return parent::delete($_where);
    }

    public function isUser() {
    $_where = array("user='{$this->_R['user']}'");
    $this->_check->ajax($this, $_where);
    }

    public function login() {
    $_where = array("user='{$this->_R['user']}'", "pass='".sha1($this->_R['pass'])."'");
    if (!$this->_check->loginCheck($this, $_where)) {
    $this->_check->error();
    } else {
    return true;
    }
    }

    public function ajaxLogin() {
    $_where = array("user='{$this->_R['user']}'", "pass='".sha1($this->_R['pass'])."'");
    $this->_check->ajaxLogin($this, $_where);
    }

    public function ajaxCode() {
    $this->_check->ajaxcode($this, $this->_R['code']);
    }
    }
    ?>
      

  2.   

    你DB类add需要俩参数,model的add只有一个参数,下一个类似
      

  3.   

    DB在这,麻烦看看 是缺什么参数,难道不是php 版本问题吗<?php
    //数据库连接类,不建议直接使用DB,而是对DB封装一层
    //这个类不会被污染,不会被直接调用
    class DB {
    //pdo对象
    private $_pdo = null;
    //用于存放实例化的对象
    static private $_instance = null;

    //公共静态方法获取实例化的对象
    static protected function getInstance() {
    if (!(self::$_instance instanceof self)) {
    self::$_instance = new self();
    }
    return self::$_instance;
    }

    //私有克隆
    private function __clone() {}

    //私有构造
    private function __construct() {
    try {
    $this->_pdo = new PDO(DB_DNS, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND=>'SET NAMES '.DB_CHARSET));
    $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    } catch (PDOException $e) {
    exit($e->getMessage());
    }
    }

    //新增
    protected function add($_tables, Array $_addData) {
    $_addFields = array();
    $_addValues = array();
    foreach ($_addData as $_key=>$_value) {
    $_addFields[] = $_key;
    $_addValues[] = $_value;
    }
    $_addFields = implode(',', $_addFields);
    $_addValues = implode("','", $_addValues);
    $_sql = "INSERT INTO $_tables[0] ($_addFields) VALUES ('$_addValues')";
    return $this->execute($_sql)->rowCount();
    }

    //修改
    protected function update($_tables, Array $_param, Array $_updateData) {
    $_where = $_setData = '';
    foreach ($_param as $_key=>$_value) {
    $_where .= $_value.' AND ';
    }
    $_where = 'WHERE '.substr($_where, 0, -4);
    foreach ($_updateData as $_key=>$_value) {
    if (Validate::isArray($_value)) {
    $_setData .= "$_key=$_value[0],";
    } else {
    $_setData .= "$_key='$_value',";
    }
    }
    $_setData = substr($_setData, 0, -1);
    $_sql = "UPDATE $_tables[0] SET $_setData $_where";
    return $this->execute($_sql)->rowCount();
    }

    //验证一条数据
    protected function isOne($_tables, Array $_param) {
    $_where = '';
    foreach ($_param as $_key=>$_value) {
    $_where .=$_value.' AND ';
    }
    $_where = 'WHERE '.substr($_where, 0, -4);
    $_sql = "SELECT id FROM $_tables[0] $_where LIMIT 1";
    return $this->execute($_sql)->rowCount();
    }

    //删除
    protected function delete($_tables, Array $_param) {
    $_where = '';
    foreach ($_param as $_key=>$_value) {
    $_where .= $_value.' AND ';
    }
    $_where = 'WHERE '.substr($_where, 0, -4);
    $_sql = "DELETE FROM $_tables[0] $_where LIMIT 1";
    return $this->execute($_sql)->rowCount();
    }

    //查询
    protected function select($_tables, Array $_fileld, Array $_param = array()) {
    $_limit = $_order = $_where = $_like = '';
    if (Validate::isArray($_param) && !Validate::isNullArray($_param)) {
    $_limit = isset($_param['limit']) ? 'LIMIT '.$_param['limit'] : '';
    $_order = isset($_param['order']) ? 'ORDER BY '.$_param['order'] : '';
    if (isset($_param['where'])) {
    foreach ($_param['where'] as $_key=>$_value) {
    $_where .= $_value.' AND ';
    }
    $_where = 'WHERE '.substr($_where, 0, -4);
    }
    if (isset($_param['like'])) {
    foreach ($_param['like'] as $_key=>$_value) {
    $_like = "WHERE $_key LIKE '%$_value%'";
    }
    }
    }
    $_selectFields = implode(',', $_fileld);
    $_table = isset($_tables[1]) ? $_tables[0].','.$_tables[1] : $_tables[0];
    $_sql = "SELECT $_selectFields FROM $_table $_where $_like $_order $_limit";
    $_stmt = $this->execute($_sql);
    $_result = array();
    while (!!$_objs = $_stmt->fetchObject()) {
    $_result[] = $_objs;
    }
    return Tool::setHtmlString($_result);
    }

    //总记录
    protected function total($_tables, Array $_param = array()) {
    $_where = '';
    if (isset($_param['where'])) {
    foreach ($_param['where'] as $_key=>$_value) {
    $_where .= $_value.' AND ';
    }
    $_where = 'WHERE '.substr($_where, 0, -4);
    }
    $_sql = "SELECT COUNT(*) as count FROM $_tables[0] $_where";
    $_stmt = $this->execute($_sql);
    return $_stmt->fetchObject()->count;
    }

    //得到下一个ID
    protected function nextId($_tables) {
    $_sql = "SHOW TABLE STATUS LIKE '$_tables[0]'";
    $_stmt = $this->execute($_sql);
    return $_stmt->fetchObject()->Auto_increment;
    } //执行SQL
    private function execute($_sql) {
    try {
    $_stmt = $this->_pdo->prepare($_sql);
    $_stmt->execute();
    } catch (PDOException  $e) {
    exit('SQL语句:'.$_sql.'<br />错误信息:'.$e->getMessage());
    }
    return $_stmt;
    }
    }
    ?>
      

  4.   


    怪了。db类他是2个参数呀, model类add却是没有