PHPStan based SQL static analysis and type inference for the database access layer.

phpstan-dba makes your phpstan static code analysis jobs aware of datatypes within your database. With this information at hand we are able to detect type inconsistencies between your domain model and database-schema. Additionally errors in code handling the results of sql queries can be detected.

This extension provides the following features, as long as you stick to the rules:

Note: At the moment only MySQL/MariaDB and PGSQL databases are supported. Technically it’s not a big problem to support other databases though.


see the ‘Files Changed’ tab of the DEMO-PR for a quick glance.


see the phpstan-dba GitHub Repository for usage instructions and setup.

💌 Support phpstan-dba

Consider supporting the project, so we can make this tool even better even faster for everyone.

Found a bug? Please help improve this article.

Previous Post
cs2pr - GitHub Pull Request annotation
Next Post
Monthly report: May 2022