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

[eluser]manish[/eluser]
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->load->database();

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

my query call is not working
#2

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

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

[eluser]manish[/eluser]
i don't want to use model i just want to run my query in helper using function

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

[eluser]xwero[/eluser]
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
Code:
$ci =& get_instance();
$ci->load->database();
$ci->db->query(’some query’);
#5

[eluser]manish[/eluser]
i have tried but it's not working is there any more setting?
#6

[eluser]xwero[/eluser]
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.
#7

[eluser]manish[/eluser]
Hey thanks it's working !!!!!!!!!!!!!!!!




Theme © iAndrew 2016 - Forum software by © MyBB