Skip to content

Commit

Permalink
Merge pull request #16 from bronek89/feature/fetch-column-mode
Browse files Browse the repository at this point in the history
Add support for FETCH_COLUMN in fetch
  • Loading branch information
muglug authored Mar 13, 2021
2 parents 24cee9c + 5aa910d commit 5241021
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/FakePdoStatementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ public function fetch(
return \array_values($row);
}

if ($fetch_style === \PDO::FETCH_COLUMN) {
$this->resultCursor++;

return \array_values($row)[0] ?? null;
}

if ($fetch_style === \PDO::FETCH_BOTH) {
$this->resultCursor++;

Expand Down
11 changes: 11 additions & 0 deletions tests/EndToEndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,17 @@ public function testFetchCountForMissingColumn(int $columnIndex)
$query->fetchColumn($columnIndex);
}

public function testFetchWithColumnMode()
{
$pdo = self::getConnectionToFullDB(false);

$query = $pdo->prepare('SELECT `id` FROM `video_game_characters` WHERE id=2 LIMIT 1');

$query->execute();

self::assertEquals(2, $query->fetch(\PDO::FETCH_COLUMN));
}

public function dataProviderTruncateForms(): \Generator
{
foreach ([
Expand Down

0 comments on commit 5241021

Please sign in to comment.