You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Creating a singleton class to wrap the database connection lets you initialize the connection once without having to then pass the connection around. This blog post has a pretty good breakdown of how this works.
Dependency injection is another option if you want to avoid singletons for testing/maintainability purposes, but imo it's 1) overkill if you don't want to support multiple DB engines at the same time (the singleton class still abstracts the DB logic from the rest of the app, so you can update in one place if desired later on), and 2) mostly proposed by people who hate on singletons due to cargo cult.
I didn't plan on making every $db call a function, but it happened.
Now I have to require
models/db.php
and$db
every time I want to query the db.I know that creates lots of redundancy.
Curious if there is a simpler solution?
The text was updated successfully, but these errors were encountered: