Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzing multiple connections #585

Closed
aszenz opened this issue Mar 21, 2023 · 6 comments
Closed

Analyzing multiple connections #585

aszenz opened this issue Mar 21, 2023 · 6 comments

Comments

@aszenz
Copy link

aszenz commented Mar 21, 2023

We use two db connections in the app, is their a way to analyze them both, i only see an option to add one pdo mysql db

@staabm
Copy link
Owner

staabm commented Mar 21, 2023

You can use https://github.com/staabm/phpstan-dba/blob/main/src/QueryReflection/ChainedReflector.php to combine several pdo or mysql,... reflectors

@aszenz
Copy link
Author

aszenz commented Mar 21, 2023

Perfect, works great.
I see it now in docs too https://github.com/staabm/phpstan-dba/blob/main/docs/reflectors.md, hence closing this issue

@aszenz aszenz closed this as completed Mar 21, 2023
@aszenz
Copy link
Author

aszenz commented Mar 24, 2023

How does phpstan-dba know which reflector to use for each file like a repository, i see some errors where it uses an incorrect reflector on the repository file and throws errors like table central.foo doesn't exist, while it should actually check demo.foo

@staabm
Copy link
Owner

staabm commented Mar 24, 2023

the chain just works thru the list of reflectors. the first one which returns a type, is used:

foreach ($this->reflectors as $reflector) {
$reflectorResult = $reflector->getResultType($queryString, $fetchType);
if (null !== $reflectorResult) {
return $reflectorResult;
}
}

I guess this might lead to problems, e.g. when you have queries which can be executed successfully on several reflectors

@aszenz
Copy link
Author

aszenz commented Mar 24, 2023

Hmm, my query should work on only one reflector, but it's not using that reflector

@staabm
Copy link
Owner

staabm commented Mar 24, 2023

please open a new issue with code which reproduces your problem.
it might be useful to create a small example repo.

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

No branches or pull requests

2 participants