Code Duplication    Length = 21-22 lines in 2 locations

db/drivers/PgsqlDriver.php 1 location

@@ 193-213 (lines=21) @@
190
     *
191
     * @return bool
192
     */
193
    public function insert($table, array $line = [], $multi = false)
194
    {
195
        $fields = '"' . implode('", "', array_keys($multi ? $line[0] : $line)) . '"';
196
        $values = ':' . implode(', :', array_keys($multi ? $line[0] : $line));
197
        $rows = $multi ? $line : [$line];
198
        $id = null;
199
200
        if ($rows) {
201
            $this->conn->beginTransaction();
202
203
            $dbh = null;
204
            foreach ($rows AS $row) {
205
                $dbh = $this->conn->prepare("INSERT INTO {$table} ({$fields}) VALUES ({$values});")->execute($row);
206
            }
207
208
            $id = $dbh ? $this->conn->lastInsertId() : false;
209
            $this->conn->commit();
210
        }
211
212
        return $id ?: false;
213
    }
214
215
    /**
216
     * Update row in table

db/drivers/MysqlDriver.php 1 location

@@ 182-203 (lines=22) @@
179
     *
180
     * @return bool
181
     */
182
    public function insert($table, array $line = [], $multi = false)
183
    {
184
        $fields = '`' . implode('`, `', array_keys($multi ? $line[0] : $line)) . '`';
185
186
        $values = ':'.implode(', :', array_keys($multi ? $line[0] : $line));
187
        $rows = $multi ? $line : [$line];
188
        $id = null;
189
190
        if ($rows) {
191
            $this->conn->beginTransaction();
192
193
            $dbh = null;
194
            foreach ($rows AS $row) {
195
                $dbh = $this->conn->prepare("INSERT INTO {$table} ({$fields}) VALUES ({$values});")->execute($row);
196
            }
197
198
            $id = $dbh ? $this->conn->lastInsertId() : false;
199
            $this->conn->commit();
200
        }
201
202
        return $id ?: false;
203
    }
204
205
    /**
206
     * Update row in table