Skip to content

Commit 5241021

Browse files
authored
Merge pull request #16 from bronek89/feature/fetch-column-mode
Add support for FETCH_COLUMN in fetch
2 parents 24cee9c + 5aa910d commit 5241021

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/FakePdoStatementTrait.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@ public function fetch(
336336
return \array_values($row);
337337
}
338338

339+
if ($fetch_style === \PDO::FETCH_COLUMN) {
340+
$this->resultCursor++;
341+
342+
return \array_values($row)[0] ?? null;
343+
}
344+
339345
if ($fetch_style === \PDO::FETCH_BOTH) {
340346
$this->resultCursor++;
341347

tests/EndToEndTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,17 @@ public function testFetchCountForMissingColumn(int $columnIndex)
901901
$query->fetchColumn($columnIndex);
902902
}
903903

904+
public function testFetchWithColumnMode()
905+
{
906+
$pdo = self::getConnectionToFullDB(false);
907+
908+
$query = $pdo->prepare('SELECT `id` FROM `video_game_characters` WHERE id=2 LIMIT 1');
909+
910+
$query->execute();
911+
912+
self::assertEquals(2, $query->fetch(\PDO::FETCH_COLUMN));
913+
}
914+
904915
public function dataProviderTruncateForms(): \Generator
905916
{
906917
foreach ([

0 commit comments

Comments
 (0)