phpstan-doctrine icon indicating copy to clipboard operation
phpstan-doctrine copied to clipboard

Enforce `Connection::executeQuery` on SELECT and `Connection::executeStatement` on others queries

Open VincentLanglet opened this issue 1 year ago • 0 comments

When using two database, one with READ/WRITE rights and one replica with READ writes, Doctrine use executeQuery/executeStatement to know which database to use. In this situation using executeQuery for UPDATE/DELETE/etc give an error about missing rights.

A thing which doesn't help to detect an error is the fact executeQuery works properly for UPDATE/DELETE/etc statement when you use only one database with READ/WRITE permission.

It would be great to report a Phpstan error if executeQuery is used on a non-select query and if executeStatement is used on a select query.

I'll try to write one for constant string, but I'm not sure it will be possible for query like 'SELECT'.$sql since the type will be simplified to string.

VincentLanglet avatar Feb 13 '24 13:02 VincentLanglet