Zend_Db_Adapter_Pdo_Abstract::exec PHP Method

exec() public method

Executes an SQL statement and return the number of affected rows
public exec ( mixed $sql ) : integer
$sql mixed The SQL statement with placeholders. May be a string or Zend_Db_Select.
return integer Number of rows that were modified or deleted by the SQL statement
    public function exec($sql)
    {
        if ($sql instanceof Zend_Db_Select) {
            $sql = $sql->assemble();
        }
        try {
            $affected = $this->getConnection()->exec($sql);
            if ($affected === false) {
                $errorInfo = $this->getConnection()->errorInfo();
                /**
                 * @see Zend_Db_Adapter_Exception
                 */
                require_once 'Zend/Db/Adapter/Exception.php';
                throw new Zend_Db_Adapter_Exception($errorInfo[2]);
            }
            return $affected;
        } catch (PDOException $e) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            require_once 'Zend/Db/Adapter/Exception.php';
            throw new Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
        }
    }

Usage Example

 /**
  * 执行SQL语句
  * 
  * @param string|Zend_Db_Select $sql
  * @param boolean $commit
  * @return integer
  */
 protected function _exec($sql, $commit = true)
 {
     $affected = $this->_db->exec($sql);
     if ($commit) {
         $this->_db->exec('COMMIT');
     }
     return $affected;
 }