Tuesday, July 6, 2010

Proxy Class

/**
 * Wrapper around Zend_Db connection that performs logging
 */
class Zend_Db_LogWrapper {
    private $conn;
    private $logger;

    public function __construct($conn, $logFilename) {
        $this->conn = $conn;
        $this->logger = new Logger($logFilename);
    }

    public function insert($table, array $bind) {
        $this->logger->logDb($table, 'insert', $bind);
        return $this->conn->insert($table, $bind);
    }

    public function update($table, array $bind, $where = '') {
        $this->logger->logDb($table, 'update', $bind, $where);
        return $this->conn->update($table, $bind, $where);
    }

    public function delete($table, $where = '') {
        $this->logger->logDb($table, 'delete', '', $where);
        return $this->conn->delete($table, $where);
    }

    /**
     * Redirect all other calls to the wrapped connection
     */
    public function __call($name, $arguments) {
        return call_user_func_array(array($this->conn, $name), $arguments);
    }
}

1 Comments:

At May 20, 2013 at 5:54 AM , Blogger David Roy said...

hey, thanks for this code, Actually i was searching this codes, finally i got it from this blog. Thanks

Indian IT Outsourcing company | Offshore Software Development Company

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home