Welcome Guest, Not a member yet? Register   Sign In
Using helper (using DB) in model
#1

[eluser]Krzemo[/eluser]
Hi,

I need a hint/tip.
I have a helper that checks DB (calls model function thats uses CI AR) and returns BOOL.
All was fine until I had to use it in a model - for adding additional condition to query.
My AR statement im doing in model gets messed up/mixed up with helper AR statement.
I assume thats all becouse im working on the same DB object instance in both places.
Any tips how to workaround it (do properly)?

Regs
K.
#2

[eluser]mddd[/eluser]
First of all, why are you using a helper to do database-stuff? Especially if the helper is calling information from a model. Just put the "helper" function in your model then!

Second, to answer your question: you can open multiple database objects in CI. Each will have its own connection.
Code:
$this->load->database('default'); // the normal way. could also be done in autoloader
$this->db->get('table');

$db2 = $this->load->database('default', true); // opens a second database object
$db2->get('table'); // that's how you use it
#3

[eluser]Krzemo[/eluser]
Quote:First of all, why are you using a helper to do database-stuff?
Requirements change/additional feature that wasn't planned in design phase...
Anyway - thnx




Theme © iAndrew 2016 - Forum software by © MyBB