Code Duplication    Length = 21-22 lines in 2 locations

db/drivers/MysqlDriver.php 1 location

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

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