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;
    }