Welcome Guest, Not a member yet? Register   Sign In
Making $db available globally
#2

You are missing some OOP notions. In your example, $db is a local variable, not a class property. You need to assign it to $this->db.

But, I wouldn't advise you to do that. Database queries should be done in models, not in controllers. CI is very flexible and won't prevent you from doing database requests everywhere, but your application will be hard to maintain and debug if you have SQL all over the place instead of following the MVC pattern.
Reply


Messages In This Thread
RE: Making $db available globally - by includebeer - 10-16-2021, 06:56 AM
RE: Making $db available globally - by sr13579 - 10-16-2021, 04:50 PM
RE: Making $db available globally - by iRedds - 10-16-2021, 09:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB