Welcome Guest, Not a member yet? Register   Sign In
how to manage DB connections
#1

(This post was last modified: 04-10-2025, 06:05 AM by PaulC.)

Hi If so how do  Team,
In my CI3 app I never worried about this because we autoloaded 'database' lib.
In CI4 it seems I now have to connect in my code - I have chosen the constructor of any Controller or Model where ever I need to access the database.
I am now aware that I could hit connection limits (currently 151 by default for mysql db)
A few (perhaps) obvious questions:
1) If I make a connection in a controller and the user session redirects to another controller will the $db persist for the session or do I open a second etc connection?
2) Should I check for an existing connection in each constructor and either proceed or open a new connection as appropriate? If so how please?
3) Another potential strategy would be to force a disconnect on completion of my db interation. If so how please?
4) I quite like the freeQuery() call. Is this recommended to optimise memory as lng as you don't need the cached result?
I have read the upgrade notes carefully but haven't found those nuggets yet.
Appreciate any thoughts and guidance.
TIA, Paul

Sorry typo in first line ...groan
Reply


Messages In This Thread
how to manage DB connections - by PaulC - 04-10-2025, 06:04 AM
RE: how to manage DB connections - by ladyangel - 04-22-2025, 05:34 AM
RE: how to manage DB connections - by bipin775 - 05-29-2025, 09:51 PM



Theme © iAndrew 2016 - Forum software by © MyBB