Help Understanding the singleton design pattern for the database connection in Yii

Can somebody help me understand how the singleton design pattern for a database connection works?

Is it a singleton for a user during a request? or any other subsequent requests by the same user?

Is it a singleton connection for many users?

thank you in advance

A singleton object only persist throughout the execution of your PHP script.

So subsequent requests to your script will still create their own singleton object.

Typically, a singleton DB instance will be created by a private static variable in the DB class and whenever you want a DB object, the private static variable holding the instance of the DB connection will be returned.

In other words, throughout your script (includes any other PHP files you load) you get the same DB object, which is a good thing to save memory and DB resources.

Hope this helps.

Thank you.