Skip to content

Commit 474132e

Browse files
committed
Added RunnableInsert::insertRows to add a huge amount of rows utilizing prepared statements. Method returns all insert ids.
1 parent 97e12c8 commit 474132e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Builder/RunnableInsert.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
namespace Kir\MySQL\Builder;
33

44
class RunnableInsert extends Insert {
5+
/**
6+
* @param array $rows
7+
* @return int[] Insert IDs
8+
*/
9+
public function insertRows(array $rows) {
10+
$result = [];
11+
$query = $this->__toString();
12+
$stmt = $this->db()->prepare($query);
13+
foreach($rows as $row) {
14+
$stmt->execute($row);
15+
$result[] = (int) $this->db()->getLastInsertId();
16+
}
17+
return $result;
18+
}
19+
520
/**
621
*/
722
public function run() {

0 commit comments

Comments
 (0)