Skip to content

Commit 981268f

Browse files
committed
- Added $params to Runnable{Delete|Insert|Update}::run() for Prepared Statements
1 parent d82cfc9 commit 981268f

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/Builder/RunnableDelete.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
class RunnableDelete extends Delete {
55
/**
6+
* @param array $params
67
* @return int
78
*/
8-
public function run() {
9+
public function run(array $params = array()) {
910
$query = (string)$this;
10-
return $this->db()->exec($query);
11+
return $this->db()->exec($query, $params);
1112
}
1213
}

src/Builder/RunnableInsert.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ public function insertRows(array $rows) {
1818
}
1919

2020
/**
21+
* @param array $params
22+
* @return int
23+
* @throws Exception
2124
*/
22-
public function run() {
25+
public function run(array $params = array()) {
2326
$query = $this->__toString();
24-
$this->db()->exec($query);
27+
$this->db()->exec($query, $params);
2528
return (int) $this->db()->getLastInsertId();
2629
}
2730
}

src/Builder/RunnableUpdate.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
class RunnableUpdate extends Update {
55
/**
6+
* @param array $params
67
* @return int
78
*/
8-
public function run() {
9+
public function run(array $params = array()) {
910
$query = $this->__toString();
10-
return $this->db()->exec($query);
11+
return $this->db()->exec($query, $params);
1112
}
1213
}

src/Databases/MySQL.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,18 @@ public function prepare($query) {
8787
* @return int
8888
*/
8989
public function exec($query, array $params = array()) {
90-
$stmt = $this->pdo->prepare($query);
91-
$timer = microtime(true);
9290
try {
91+
$stmt = $this->pdo->prepare($query);
92+
$timer = microtime(true);
9393
$stmt->execute($params);
94+
$this->queryLoggers->log($query, microtime(true) - $timer);
95+
$result = $stmt->rowCount();
96+
$stmt->closeCursor();
97+
return $result;
9498
} catch (PDOException $e) {
9599
$this->exceptionInterpreter->throwMoreConcreteException($e);
100+
throw $e;
96101
}
97-
$this->queryLoggers->log($query, microtime(true) - $timer);
98-
$result = $stmt->rowCount();
99-
$stmt->closeCursor();
100-
return $result;
101102
}
102103

103104
/**

0 commit comments

Comments
 (0)