How to avoid opening multiple connections to the DB with OOP PHP

前端 未结 3 2034
失恋的感觉
失恋的感觉 2021-02-09 10:35

I\'ve been a procedural programmer for over 4 yrs and it\'s time to start looking into OOP. With that said, let\'s say I needed to call two methods in my class. Each method requ

3条回答
  •  臣服心动
    2021-02-09 10:51

    You should look into a manager class for your db connections. Then you can have one central place where you request connections from. If there is already an open connection the manager can return that instead of returning a new connection.

    This would be one approach. There are tons of examples out there about how to implement something like this. There already some for mysql and mssql. But you could surely extend for your db.

提交回复
热议问题