public function insert($table, array $data)
    {
        $context = $this->getCommandContext();
        $context->table    = $table;
        $context->data        = $data;
        $context->operation    = AnDatabase::OPERATION_INSERT;

        //Excute the insert operation
        if ($this->getCommandChain()->run('before.insert', $context) !== false) {
            //Check if we have valid data to insert, if not return false
            if (count($context->data)) {
                foreach ($context->data as $key => $val) {
                    $vals[] = $this->quoteValue($val);
                    $keys[] = '`'.$key.'`';
                }

                $context->query = 'INSERT INTO '.$this->quoteName($this->getTableNeedle().$context->table)
                     . '('.implode(', ', $keys).') VALUES ('.implode(', ', $vals).')';

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

                $context->affected = $this->_affected_rows;

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

        return $context->affected;
    }
public function insert($table, array $data)
    {
        $context = $this->getCommandContext();
        $context->table    = $table;
        $context->data        = $data;
        $context->operation    = AnDatabase::OPERATION_INSERT;

        //Excute the insert operation
        if ($this->getCommandChain()->run('before.insert', $context) !== false) {
            //Check if we have valid data to insert, if not return false
            if (count($context->data)) {
                foreach ($context->data as $key => $val) {
                    $vals[] = $this->quoteValue($val);
                    $keys[] = '`'.$key.'`';
                }

                $context->query = 'INSERT INTO '.$this->quoteName($this->getTableNeedle().$context->table)
                     . '('.implode(', ', $keys).') VALUES ('.implode(', ', $vals).')';

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

                $context->affected = $this->_affected_rows;

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

        return $context->affected;
    }
public function insert ( $ table , array $ data ) { $ context = $ this -> getCommandContext ( ) ; $ context -> table = $ table ; $ context -> data = $ data ; $ context -> operation = AnDatabase :: OPERATION_INSERT ; //Excute the insert operation if ( $ this -> getCommandChain ( ) -> run ( 'before.insert' , $ context ) !== false ) { //Check if we have valid data to insert, if not return false if ( count ( $ context -> data ) ) { foreach ( $ context -> data as $ key => $ val ) { $ vals [ ] = $ this -> quoteValue ( $ val ) ; $ keys [ ] = '`' . $ key . '`' ; } $ context -> query = 'INSERT INTO ' . $ this -> quoteName ( $ this -> getTableNeedle ( ) . $ context -> table ) . '(' . implode ( ', ' , $ keys ) . ') VALUES (' . implode ( ', ' , $ vals ) . ')' ; //Execute the query $ context -> result = $ this -> execute ( $ context -> query ) ; $ context -> affected = $ this -> _affected_rows ; $ this -> getCommandChain ( ) -> run ( 'after.insert' , $ context ) ; } else { $ context -> affected = false ; } } return $ context -> affected ; }
Inserts a row of data into a table.

Automatically quotes the data values

@param string  	The table to insert data into.
@param array 	An associative array where the key is the colum name and
the value is the value to insert for that column.
@return bool|integer  If the insert query was executed returns the number of rows updated, or 0 if
no rows where updated, or -1 if an error occurred. Otherwise FALSE.
Inserts a row of data into a table .