php singleton database connection, is this code bad practice?

前端 未结 4 1783
天命终不由人
天命终不由人 2020-12-06 20:18

I\'m trying to create a simple to use singleton class to connect to mysql database and do queries, the code works fine and i haven\'t had any problems with it, but since I\'

4条回答
  •  情歌与酒
    2020-12-06 20:52

    The only positive argument I've heard for the Singleton design pattern in PHP was from a developer who implemented a Singleton database connection in conjunction with a Memcached object. I didn't actually get a chance to look at the code and performance but he was able to put forward a coherent argument.

    Personally I don't believe that the Singleton design pattern is very relevant to PHP, which is largely stateless anyway (as pointed out before each request will have a singleton).

提交回复
热议问题