Skip to content

Commit c40a6aa

Browse files
committed
- DatabaseStatement::execute now returns $this instead of bool. If the result of PDOStatement::execute is != true, DatabaseStatement::execute throws an exception from now on
1 parent 7bc4e4c commit c40a6aa

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/Builder/QueryStatement.php

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

44
use Kir\MySQL\Databases\MySQL\MySQLExceptionInterpreter;
5+
use Kir\MySQL\Exceptions\SqlException;
56
use PDO;
67
use PDOException;
78
use PDOStatement;
@@ -40,15 +41,19 @@ public function getStatement() {
4041

4142
/**
4243
* @param array $params
43-
* @return bool
44+
* @throws SqlException
45+
* @return $this
4446
*/
4547
public function execute(array $params = []) {
46-
return $this->exceptionHandler(function() use ($params) {
48+
$this->exceptionHandler(function() use ($params) {
4749
$timer = microtime(true);
4850
$response = $this->statement->execute($params);
4951
$this->queryLoggers->log($this->query, microtime(true)-$timer);
50-
return $response;
52+
if(!$response) {
53+
throw new SqlException('Execution returned with "false".');
54+
}
5155
});
56+
return $this;
5257
}
5358

5459
/**

src/Database/DatabaseStatement.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Kir\MySQL\Database;
33

4+
use Kir\MySQL\Exceptions\SqlException;
45
use PDO;
56
use PDOStatement;
67

@@ -12,7 +13,8 @@ public function getStatement();
1213

1314
/**
1415
* @param array $params
15-
* @return bool
16+
* @throws SqlException
17+
* @return $this
1618
*/
1719
public function execute(array $params = []);
1820

0 commit comments

Comments
 (0)