Is there a use-case for singletons with database access in PHP?

后端 未结 11 2051
名媛妹妹
名媛妹妹 2020-11-21 06:44

I access my MySQL database via PDO. I\'m setting up access to the database, and my first attempt was to use the following:

The first thing I thought of is glob

11条回答
  •  孤城傲影
    2020-11-21 07:26

    Your interpretation is correct. Singletons have their place but are overused. Often, accessing static member functions is sufficient (notably, when you do not need to control time-of-construction in any way). Better, you can just put some free functions and variables in a namespace.

提交回复
热议问题