Browse Source

Update DB\AbstractStatement #9

In the case of -> fetch (PDO :: FETCH_COLUMN), the method should return the value from the first column of the row, not an array with the data of all columns of the row.
Visman 3 years ago
parent
commit
2073aceed7
1 changed files with 9 additions and 1 deletions
  1. 9 1
      app/Core/DB/AbstractStatement.php

+ 9 - 1
app/Core/DB/AbstractStatement.php

@@ -29,7 +29,11 @@ abstract class AbstractStatement extends DBStatement
 
 
     protected function dbFetch(int $mode, int $cursorOrientation, int $cursorOffset) /* : mixed */
     protected function dbFetch(int $mode, int $cursorOrientation, int $cursorOffset) /* : mixed */
     {
     {
-        $data = parent::fetch($mode, $cursorOrientation, $cursorOffset);
+        $data = parent::fetch(
+            PDO::FETCH_COLUMN === $mode ? PDO::FETCH_NUM : $mode,
+            $cursorOrientation,
+            $cursorOffset
+        );
 
 
         if (! \is_array($data)) {
         if (! \is_array($data)) {
             return $data;
             return $data;
@@ -61,6 +65,10 @@ abstract class AbstractStatement extends DBStatement
 
 
         unset($value);
         unset($value);
 
 
+        if (PDO::FETCH_COLUMN === $mode) {
+            $data = $data[0];
+        }
+
         return $data;
         return $data;
     }
     }