What are the advantages to passing a global DB connection into each function of a model?

I am working with an older code base that passed a db connection into most functions in each class of the models. The db connection is created as a global and passed everywhere in the application:

$user = new User();
$user->loadById($db, $userId);

What advantages do we get by doing this vs a single connection the entire model inherits similar to the way most frameworks currently work?

Any insight would be very helpful.


Source: oop

Leave a Reply