src/SqlQueryBuilder.php
/**
     * Creates an "INSERT - ON DUPLICATE KEY UPDATE" query
     */
Creates an "INSERT - ON DUPLICATE KEY UPDATE" query
Creates an " INSERT - ON DUPLICATE KEY UPDATE " query
public function upsert(string $table, array $attributes, ?array $fieldsToUpdate = null): self
    {
        $this->insert = $this->update = $table;
        foreach($attributes as $field => $value){
            $this->values[$field] = '?';
            $this->params[] = $value;
        }
        foreach($attributes as $field => $value){
            if($fieldsToUpdate === null || in_array($field, $fieldsToUpdate)){
                $this->set[$field] = '?';
                $this->params[] = $value;
            }
        }
        return $this;
    }
public function upsert ( string $ table , array $ attributes , ? array $ fieldsToUpdate = null ) : self { $ this -> insert = $ this -> update = $ table ; foreach ( $ attributes as $ field => $ value ) { $ this -> values [ $ field ] = '?' ; $ this -> params [ ] = $ value ; } foreach ( $ attributes as $ field => $ value ) { if ( $ fieldsToUpdate === null || in_array ( $ field , $ fieldsToUpdate ) ) { $ this -> set [ $ field ] = '?' ; $ this -> params [ ] = $ value ; } } return $ this ; }
Creates an "INSERT - ON DUPLICATE KEY UPDATE" query
Creates an " INSERT - ON DUPLICATE KEY UPDATE " query
//Prepare INSERT first //Prepare UPDATE