Skip to content

Commit

Permalink
Throw exception if get_column returns multiple columns
Browse files Browse the repository at this point in the history
  • Loading branch information
David Vandemaele committed Feb 23, 2021
1 parent 6203ea5 commit f77b0fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Skeleton/Database/Driver/Mysqli/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ public function get_column($query, $params = []) {
$statement->execute();
$result = $statement->fetch_assoc();

if (count($result) == 0) {
return [];
} elseif (count($result[0]) != 1) {
throw new \Exception('Resultset has more than 1 column');
}

$col = [];
foreach ($result as $row) {
$col[] = array_shift($row);
Expand Down
6 changes: 6 additions & 0 deletions lib/Skeleton/Database/Driver/Pdo/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,12 @@ public function get_column($query, $params = []) {
$statement->execute();
$result = $statement->fetch_assoc();

if (count($result) == 0) {
return [];
} elseif (count($result[0]) != 1) {
throw new \Exception('Resultset has more than 1 column');
}

$col = [];
foreach ($result as $row) {
$col[] = array_shift($row);
Expand Down

0 comments on commit f77b0fe

Please sign in to comment.