src/AbstractModel.php
public function insert(array $data = array(), $update = false)
    {
        $this->viewCheck(__FUNCTION__);

        $data = array_merge($this->_schema['init'],
            array_filter($this->_schema['values'], array($this, 'filterRule')),
            array_filter($this->_schema['others'], array($this, 'filterRule')),
            $data);

        $params = array();
        foreach ($data as $key => $value)
            if (in_array($key, $this->_properties['primary_key']) && !$value)
                continue;
            elseif (is_array($value))
                return false;
            elseif (isset($this->_properties['fields'][$key]))
                $params[':'.$key] = $value;

        if (empty($params) || ($update && !$this->_properties['primary_key']))
            return false;

        $query = $this->buildInsert($params, $update);

        if (!($query && $this->validate($params)))
            return false;

        $old = clone $this;
        if (!$this->beforeInsert($params))
            return false;

        if ($result = $this->run($query, $params))
            $this->assign($params);

        if (!$this->afterInsert($old))
            return false;

        return $result;
    }
public function insert(array $data = array(), $update = false)
    {
        $this->viewCheck(__FUNCTION__);

        $data = array_merge($this->_schema['init'],
            array_filter($this->_schema['values'], array($this, 'filterRule')),
            array_filter($this->_schema['others'], array($this, 'filterRule')),
            $data);

        $params = array();
        foreach ($data as $key => $value)
            if (in_array($key, $this->_properties['primary_key']) && !$value)
                continue;
            elseif (is_array($value))
                return false;
            elseif (isset($this->_properties['fields'][$key]))
                $params[':'.$key] = $value;

        if (empty($params) || ($update && !$this->_properties['primary_key']))
            return false;

        $query = $this->buildInsert($params, $update);

        if (!($query && $this->validate($params)))
            return false;

        $old = clone $this;
        if (!$this->beforeInsert($params))
            return false;

        if ($result = $this->run($query, $params))
            $this->assign($params);

        if (!$this->afterInsert($old))
            return false;

        return $result;
    }
public function insert ( array $ data = array ( ) , $ update = false ) { $ this -> viewCheck ( __FUNCTION__ ) ; $ data = array_merge ( $ this -> _schema [ 'init' ] , array_filter ( $ this -> _schema [ 'values' ] , array ( $ this , 'filterRule' ) ) , array_filter ( $ this -> _schema [ 'others' ] , array ( $ this , 'filterRule' ) ) , $ data ) ; $ params = array ( ) ; foreach ( $ data as $ key => $ value ) if ( in_array ( $ key , $ this -> _properties [ 'primary_key' ] ) && ! $ value ) continue ; elseif ( is_array ( $ value ) ) return false ; elseif ( isset ( $ this -> _properties [ 'fields' ] [ $ key ] ) ) $ params [ ':' . $ key ] = $ value ; if ( empty ( $ params ) || ( $ update && ! $ this -> _properties [ 'primary_key' ] ) ) return false ; $ query = $ this -> buildInsert ( $ params , $ update ) ; if ( ! ( $ query && $ this -> validate ( $ params ) ) ) return false ; $ old = clone $ this ; if ( ! $ this -> beforeInsert ( $ params ) ) return false ; if ( $ result = $ this -> run ( $ query , $ params ) ) $ this -> assign ( $ params ) ; if ( ! $ this -> afterInsert ( $ old ) ) return false ; return $ result ; }
Insert, on duplicate key update
Insert on duplicate key update