FinaleExec.class.php 1.88 KB
<?php

/**
 * 执行最终的操作方法
 *
 * example:
 *   <pre>
 *
 *   </pre>
 *
 * @name Util_Dao_Db_FinaleExec
 * @version 448 (2009-4-17 下午02:24:48)
 * @package Q.Dao.Db.FinaleExec
 * @author Peter.zyliu liuziyang@zadooo.com
 * @since 1.0
 */
final class Util_Dao_Db_FinaleExec {

    /**
    * pdo对象
    *
    * @var object
    */
    private $pdo;

    /**
     * Enter description here...
     *
     * @var object
     */
    private $stmt;

    /**
     * 返回sql执行状态
     *
     * @var bool
     */
    private $retval;

    /**
     * 初始化
     *
     * @param Zend_Db::factory() $pdo
     * @param Zend_Db::factory() $stmt
     */
    public function __construct($pdo, $stmt,$retval=true) {
        if(!is_object($pdo) || !is_object($stmt) ) {
            throw new Util_Dao_Exception ( 'FinaleExec :\$pdo or \$stmt not\'s object ');
        }
        $this->pdo = $pdo;
        $this->stmt = $stmt;
        $this->retval = $retval;
    }

    /**
     * 返回插入影响的行数
     * @return integer
     */
    public function rowCount() {
        return $this->stmt->rowCount ();
    }

    /**
     * 获取刚刚插入的数据ID
     * @return Integer
     */
    public function lastInsertId() {
        return $this->pdo->lastInsertId ();
    }

    /**
     * 返回执行sql的状态
     * @return bool
     */
    public function status() {
        return $this->retval;
    }

    /**
     * 返回错误码
     * @return String
     */
    public function errorCode() {
        return $this->stmt->errorCode ();
    }

    /**
     * 返回错误信息
     * @return Array
     */
    public function errorInfo() {
        return $this->stmt->errorInfo ();
    }

    /**
     *
     * @param <type> $name
     * @param <type> $arg
     */
    public function __call($name, $arg) {
        throw new Util_Dao_Exception ( 'FinaleExec :not ' .$name);
    }
}