public function update($table, array $data, $where = null)
    {
        $context = $this->getCommandContext();
        $context->table    = $table;
        $context->data    = $data;
        $context->where    = $where;
        $context->operation    = AnDatabase::OPERATION_UPDATE;

        //Excute the update operation
        if ($this->getCommandChain()->run('before.update', $context) !==  false) {
            if (count($context->data)) {
                foreach ($context->data as $key => $val) {
                    $vals[] = '`'.$key.'` = '.$this->quoteValue($val);
                }

                //Create query statement
                $context->query = 'UPDATE '.$this->quoteName($this->getTableNeedle().$context->table)
                    .' SET '.implode(', ', $vals)
                    .' '.$context->where
                ;

                //Execute the query
                $context->result = $this->execute($context->query);

                $context->affected = $this->_affected_rows;
                $this->getCommandChain()->run('after.update', $context);
            } else {
                $context->affected = false;
            }
        }

        return $context->affected;
    }
public function update($table, array $data, $where = null)
    {
        $context = $this->getCommandContext();
        $context->table    = $table;
        $context->data    = $data;
        $context->where    = $where;
        $context->operation    = AnDatabase::OPERATION_UPDATE;

        //Excute the update operation
        if ($this->getCommandChain()->run('before.update', $context) !==  false) {
            if (count($context->data)) {
                foreach ($context->data as $key => $val) {
                    $vals[] = '`'.$key.'` = '.$this->quoteValue($val);
                }

                //Create query statement
                $context->query = 'UPDATE '.$this->quoteName($this->getTableNeedle().$context->table)
                    .' SET '.implode(', ', $vals)
                    .' '.$context->where
                ;

                //Execute the query
                $context->result = $this->execute($context->query);

                $context->affected = $this->_affected_rows;
                $this->getCommandChain()->run('after.update', $context);
            } else {
                $context->affected = false;
            }
        }

        return $context->affected;
    }
public function update ( $ table , array $ data , $ where = null ) { $ context = $ this -> getCommandContext ( ) ; $ context -> table = $ table ; $ context -> data = $ data ; $ context -> where = $ where ; $ context -> operation = AnDatabase :: OPERATION_UPDATE ; //Excute the update operation if ( $ this -> getCommandChain ( ) -> run ( 'before.update' , $ context ) !== false ) { if ( count ( $ context -> data ) ) { foreach ( $ context -> data as $ key => $ val ) { $ vals [ ] = '`' . $ key . '` = ' . $ this -> quoteValue ( $ val ) ; } //Create query statement $ context -> query = 'UPDATE ' . $ this -> quoteName ( $ this -> getTableNeedle ( ) . $ context -> table ) . ' SET ' . implode ( ', ' , $ vals ) . ' ' . $ context -> where ; //Execute the query $ context -> result = $ this -> execute ( $ context -> query ) ; $ context -> affected = $ this -> _affected_rows ; $ this -> getCommandChain ( ) -> run ( 'after.update' , $ context ) ; } else { $ context -> affected = false ; } } return $ context -> affected ; }
Updates a table with specified data based on a WHERE clause

Automatically quotes the data values

@param string 	The table to update
@param array  	An associative array where the key is the column name and
the value is the value to use ofr that column.
@param mixed 	A sql string or AnDatabaseQuery object to limit which rows are updated.
@return integer  If the update query was executed returns the number of rows updated, or 0 if
no rows where updated, or -1 if an error occurred. Otherwise FALSE.
Updates a table with specified data based on a WHERE clause