Skip to content

Commit 865ad5d

Browse files
staabmclxmstaab
andauthored
PDO: support PDO::FETCH_COLUMN in fetch() (#302)
Co-authored-by: Markus Staab <[email protected]>
1 parent 62e90f4 commit 865ad5d

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private function inferType(MethodReflection $methodReflection, MethodCall $metho
7878
}
7979
}
8080

81-
if ('fetchAll' === $methodReflection->getName() && QueryReflector::FETCH_TYPE_COLUMN === $fetchType) {
81+
if (QueryReflector::FETCH_TYPE_COLUMN === $fetchType) {
8282
$columnIndex = 0;
8383

8484
if (\count($args) > 1) {

tests/default/data/pdo-stmt-fetch.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ public function fetch(PDO $pdo)
6363
$all = $stmt->fetch(PDO::FETCH_ASSOC);
6464
assertType('array{email: string, adaid: int<0, 4294967295>}|false', $all);
6565

66+
$all = $stmt->fetch(PDO::FETCH_COLUMN);
67+
assertType('string|false', $all);
68+
69+
$all = $stmt->fetch(PDO::FETCH_COLUMN, 0);
70+
assertType('string|false', $all);
71+
72+
$all = $stmt->fetch(PDO::FETCH_COLUMN, 1);
73+
assertType('int<0, 4294967295>|false', $all);
74+
6675
// not yet supported fetch types
6776
$all = $stmt->fetch(PDO::FETCH_OBJ);
6877
assertType('mixed', $all);

tests/rules/config/.phpstan-dba-mysqli.cache

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)