Answer the question
In order to leave comments, you need to log in
How many instances of one class can be created?
There is a class "DataBase" the appeal goes by the method of chaining.
I do it like this:
$db = DataBase::instance();
$db->table('users')->get();
$db = new DataBase;
$db->table('users')->get();
$validation = Validation::instance();
$validation->validate($_POST,$rules);
Answer the question
In order to leave comments, you need to log in
do you think there are situations when you need to have two connections in a script to two different databases?
in my opinion, this situation is quite real
, but making a class for working with subd alone is not right
Despite the fact that the singleton is an anti-pattern, it is indispensable in development.
Specifically, in this case, the scheme is as follows:
- the connection to the database is stored in the singleton = DbConnection
- the querybuilder creates new objects itself, but uses the DbConnection
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question