PHP mySQL - When is the best time to disconnect from the database?

前端 未结 6 611
抹茶落季
抹茶落季 2020-12-03 17:08

I use lazy connection to connect to my DB within my DB object. This basically means that it doesn\'t call mysql_connect() until the first query is handed to it, and

6条回答
  •  Happy的楠姐
    2020-12-03 17:35

    Using a lazy connection is probably a good idea, since you may not need the database connection at all for some script executions.

    On the other hand, once it's open, leave it open, and either close it explicitly as the script ends, or allow PHP to clean up the connection - having an open connection isn't going to harm anything, and you don't want to incur the unnecessary overhead of checking and re-establishing a connection if you are querying the database a second time.

提交回复
热议问题