public function save($table, $data, $id = 'id', $auto_id = true)
    {
        // Update
        if (isset($data[$id]) && $this->getFieldById($table, $id, $this->escape($data[$id]), $id) !== false) {
            try {
                return $this->updateById($table, $data, $id);
            } catch (\Exception $e) {
                throw $e;
            }

            // Insert
        } else {
            try {
                if ($auto_id) {
                    unset($data[$id]);
                }
                return $this->insertId($table, $data);
            } catch (\Exception $e) {
                throw $e;
            }
        }
    }
public function save($table, $data, $id = 'id', $auto_id = true)
    {
        // Update
        if (isset($data[$id]) && $this->getFieldById($table, $id, $this->escape($data[$id]), $id) !== false) {
            try {
                return $this->updateById($table, $data, $id);
            } catch (\Exception $e) {
                throw $e;
            }

            // Insert
        } else {
            try {
                if ($auto_id) {
                    unset($data[$id]);
                }
                return $this->insertId($table, $data);
            } catch (\Exception $e) {
                throw $e;
            }
        }
    }
public function save ( $ table , $ data , $ id = 'id' , $ auto_id = true ) { // Update if ( isset ( $ data [ $ id ] ) && $ this -> getFieldById ( $ table , $ id , $ this -> escape ( $ data [ $ id ] ) , $ id ) !== false ) { try { return $ this -> updateById ( $ table , $ data , $ id ) ; } catch ( \ Exception $ e ) { throw $ e ; } // Insert } else { try { if ( $ auto_id ) { unset ( $ data [ $ id ] ) ; } return $ this -> insertId ( $ table , $ data ) ; } catch ( \ Exception $ e ) { throw $ e ; } } }
Saving to DB by Id
existing entry => update, else => insert
@param $table
@param $data
@param string $id
@param bool $auto_id
@return mixed|string
@throws \Exception
Saving to DB by Id existing entry = > update else = > insert