As a rule, I tend to open and close a connection based on what I&#39;m doing with the database. If I were to directly run a series of queries one after another, I would keep it open until a change in interface (referring to changes in objects, both masters and slaves). <div>
Also, you can perform any query that does not change any records safely without a commit, for example, searches. For everything else, you need to call commit - but you don&#39;t need to close the connection.</div>