Welcome Guest, Not a member yet? Register   Sign In
active record class as multiple objects, or a small tweak or hack or whatever
#1

[eluser]tmsajin[/eluser]
hi,
i recently found this method myself,
normally we are using $this->db for active record operations,
and this is i tried,
Code:
// call for active record class using DB() function
   $ndb = DB(); // $ndb is now an independent active record class object
  
   $ndb->select('pptc_fixed_id as id');

   $this->db->select('nonexisting_table'); // this one not affect $ndb

   $ndb->select('pptc_type_name as name');
   $ndb->from('property_category');
   $rs = $ndb->get();

i was thinking , using this way , any method for making union query with multiple db objects. please post your suggestions.
sajin tm
#2

[eluser]TheFuzzy0ne[/eluser]
Please check out the "[url="http://focusonfacts.thefuzzy0ne.za.net/user_guide/database/connecting.html"]Connecting to multiple databases[/url]" section in the user guide.
#3

[eluser]tmsajin[/eluser]
i checked that page , i was meaning about how to make union query , suppose if we have multiple select queries as different object , then union query making would be possible or not without any tweak in the existing system.
#4

[eluser]phazei[/eluser]
Ever find anything? Or did you just end up doing the query manually?
#5

[eluser]Nicholai[/eluser]
I need to do this as well. I dug through DB_active_rec.php a bit, and there are no functions to perform a union. I imagine it would be implemented as another function that doesn't require any parameters and just adds the word ' UNION ' to the string to be evaluated. I'm not brave enough to try messing with the core class. Is it possible to extend the Active Record class?
#6

[eluser]kgill[/eluser]
Honestly, just forgo AR for that and write out the query, you'll save yourself time and headache.

I'll spare you my active record rant Tongue
#7

[eluser]tmsajin[/eluser]
i just tried a union query with Active record class ,

Code:
function test_union(){
        $d1 = DB();
        $d1->select(" now() as f1");
        $d1->get();
        $d2 = DB();
        $d2->select(" version() as f1");
        $d2->get();
        $union = $d1->last_query()." union ".$d2->last_query();
        echo $union;
    }
this will output

SELECT now() as f1
union
SELECT version() as f1


;-)
#8

[eluser]jet_black82[/eluser]
[quote author="tmsajin" date="1240146913"]i just tried a union query with Active record class ,

Code:
function test_union(){
        $d1 = DB();
        $d1->select(" now() as f1");
        $d1->get();
        $d2 = DB();
        $d2->select(" version() as f1");
        $d2->get();
        $union = $d1->last_query()." union ".$d2->last_query();
        echo $union;
    }
this will output

SELECT now() as f1
union
SELECT version() as f1


;-)[/quote]

that is an UNION ALL not an UNION Tongue




Theme © iAndrew 2016 - Forum software by © MyBB