Welcome Guest, Not a member yet? Register   Sign In
how to run query within helper

Hi , i have created one helper where i want to face some recored from database any one can help me in this tried this


$this->db->query('some query');
but i have not getting any result

my query call is not working

the helper functions don't load the CI object by default like controllers or models so you have to import it using
$ci =& get_instance();

If your database is already loaded you can load the model and start using its methods.

i don't want to use model i just want to run my query in helper using function

this->db->query(’some query’);

Normally a helper with a query is a part of a custom library and if the library is build following the rules you would already have a model and 90% of the time there would already be a method that provides the data you need for your helper.

But if you don't want a model you still have to get the CI object an chain everything of that
$ci =& get_instance();
$ci->db->query(’some query’);

i have tried but it's not working is there any more setting?

the next setting is the model but you should be able to use it. Try to autoload the database or add it to the controller. I've noticed a few times load doesn't work in libraries maybe it's the same with helpers.

Hey thanks it's working !!!!!!!!!!!!!!!!

Theme © iAndrew 2016 - Forum software by © MyBB