Skip to content

A single DB connection instead of multiple connections #53

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

colshrapnel
Copy link

Connecting in every data class is a sure bad practice, and anyone who would try to extend the previously used approach to other classes will end up with tens of simultaneous connections to the database from the same PHP instance.

So a database connection should be instantiated only once and then passed to all objects as a constructor parameter.

Given this lesson is linked on the PHPTheRightWay, it shouldn't promote a bad practice, even for sake of simplification.

…ery class

Connecting in every data class is a sure bad practice, and anyone who would try to extend the previously used approach to other classes will end up with tens of simultaneous connections to the database from the same PHP instance. 

So a database connection should be instantiated only once and then passed to all objects as a constructor parameter.

Given this lesson is linked on the PHPTheRightWay, it shouldn't promote a bad practice, even for sake of simplification.
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