Skip to content

Commit f77b0fe

Browse files
author
David Vandemaele
committed
Throw exception if get_column returns multiple columns
1 parent 6203ea5 commit f77b0fe

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/Skeleton/Database/Driver/Mysqli/Proxy.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@ public function get_column($query, $params = []) {
418418
$statement->execute();
419419
$result = $statement->fetch_assoc();
420420

421+
if (count($result) == 0) {
422+
return [];
423+
} elseif (count($result[0]) != 1) {
424+
throw new \Exception('Resultset has more than 1 column');
425+
}
426+
421427
$col = [];
422428
foreach ($result as $row) {
423429
$col[] = array_shift($row);

lib/Skeleton/Database/Driver/Pdo/Proxy.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,12 @@ public function get_column($query, $params = []) {
502502
$statement->execute();
503503
$result = $statement->fetch_assoc();
504504

505+
if (count($result) == 0) {
506+
return [];
507+
} elseif (count($result[0]) != 1) {
508+
throw new \Exception('Resultset has more than 1 column');
509+
}
510+
505511
$col = [];
506512
foreach ($result as $row) {
507513
$col[] = array_shift($row);

0 commit comments

Comments
 (0)