php singleton database connection, is this code bad practice?

前端 未结 4 1772
天命终不由人
天命终不由人 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 21:02

    This pattern will be fine because the singleton will only apply to the current user session. The decision really comes down to what your priority is. If you want faster performance for the user then you want to allow more database connections per user, but if you want to limit how hard your database gets hit then the singleton gives you a good middle of the road.

提交回复
热议问题