PHPackages                             staabm/phpstan-dba - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. staabm/phpstan-dba

ActivePhpstan-extension[Testing &amp; Quality](/categories/testing)

staabm/phpstan-dba
==================

0.4.2(10mo ago)2922.5M↓52.5%24[68 issues](https://github.com/staabm/phpstan-dba/issues)[21 PRs](https://github.com/staabm/phpstan-dba/pulls)2MITPHPPHP ^7.4 || ^8.0CI passing

Since Jan 7Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/staabm/phpstan-dba)[ Packagist](https://packagist.org/packages/staabm/phpstan-dba)[ GitHub Sponsors](https://github.com/staabm)[ RSS](/packages/staabm-phpstan-dba/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (14)Versions (134)Used By (2)

`phpstan-dba`: PHPStan based SQL static analysis and type inference for the database access layer
=================================================================================================

[](#phpstan-dba-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](https://staabm.github.io/2022/07/23/phpstan-dba-inference-placeholder.html#the-golden-phpstan-dba-rules):

- [result set type-inference](https://staabm.github.io/2022/06/19/phpstan-dba-type-inference.html)
- [detect errors in sql queries](https://staabm.github.io/2022/08/05/phpstan-dba-syntax-error-detection.html)
- [detect placeholder/bound value mismatches](https://staabm.github.io/2022/07/30/phpstan-dba-placeholder-validation.html)
- [query plan analysis](https://staabm.github.io/2022/08/16/phpstan-dba-query-plan-analysis.html) to detect performance issues
- builtin support for `doctrine/dbal`, `mysqli`, and `PDO`
- API to configure the same features for your custom sql based database access layer
- Opt-In analysis of write queries (since version 0.2.55+)

In case you are using Doctrine ORM, you might use `phpstan-dba` in tandem with [phpstan-doctrine](https://github.com/phpstan/phpstan-doctrine).

Note

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

Talks
-----

[](#talks)

[phpstan-dba - check your sql queries like a boss](https://staabm.github.io/talks/phpstan-dba@phpugffm/)May 2023, at PHP Usergroup in Frankfurt Main (Germany).

DEMO
----

[](#demo)

see the ['Files Changed' tab of the DEMO-PR](https://github.com/staabm/phpstan-dba/pull/61/files#diff-98a3c43049f6a0c859c0303037d9773534396533d7890bad187d465d390d634e) for a quick glance.

💌 Support phpstan-dba
---------------------

[](#-support-phpstan-dba)

[Consider supporting the project](https://github.com/sponsors/staabm), so we can make this tool even better even faster for everyone.

Installation
------------

[](#installation)

**First**, use composer to install:

```
composer require --dev staabm/phpstan-dba
```

**Second**, create a `phpstan-dba-bootstrap.php` file, which allows to you to configure `phpstan-dba` (this optionally includes database connection details, to introspect the database; if you would rather not do this see [Record and Replay](https://github.com/staabm/phpstan-dba/blob/main/docs/record-and-replay.md):

```
