Skip to content

Track what DBAL queries store in each column and what they read back - #169

Merged
danog merged 6 commits into
psalm:2.xfrom
danog:database-query-annotations
Nov 20, 2026
Merged

danog merged 6 commits into
psalm:2.xfrom
danog:database-query-annotations

Conversation

@danog

@danog danog commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

What a DBAL query stores isn't reported where a query reads it back.

Before

<?php
use Doctrine\DBAL\Connection;

function store(Connection $db): void {
    $db->executeStatement('INSERT INTO comments (author, body) VALUES (?, ?)', ['admin', $_GET['body']]);
}

function show(Connection $db): void {
    $row = $db->fetchAssociative('SELECT author, body FROM comments');
    if ($row !== false) {
        echo (string) $row['body']; // no issue
    }
}

After

        echo (string) $row['body']; // TaintedHtml

The other columns stay clean. The same for the other fetch*()/iterate*() methods and executeQuery() of Connection, and, with DBAL 4, for prepared statements (bindValue(), executeQuery(), executeStatement()) and the rows of their Result.

Needs Psalm 7.13, with vimeo/psalm#14159 (@psalm-database-*).

@danog
danog marked this pull request as ready for review November 20, 2026 22:33
@danog
danog merged commit 828b551 into psalm:2.x Nov 20, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant