For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > August 2006 > Re: [PEAR] DB_DataObject - Table alias in joined query









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PEAR] DB_DataObject - Table alias in joined query
Jan Wagner

2006-08-23, 3:58 am

> Doing this :
> <?php
> $cat = & DB_DataObject::factory('ent_categorie');

> $fcat = & DB_DataObject::factory('ent_categorie');

>
> $cat->selectAdd();
> $cat->selectAdd('ent_categorie.*');
> $cat->joinAdd($fcat,'right','fcat');
>
> $cat->selectAs($fcat,'ent_categorie__%s');
> ?>


> This is still not what I need. The alias is used for the WHERE
> clause, not for the select fields.
> What I would want is :
> SELECT ent_categorie.* , fcat.id as ent_categorie__id , fcat.titre as
> ent_categorie__titre , fcat.strip as
> ent_categorie__strip ,fcat.active as ent_categorie__active ,
> fcat.categorie_id as ent_categorie__categorie_id , fcat.gauche as
> ent_categorie__gauche , fcat.droite as ent_categorie__droite ,
> fcat.path as ent_categorie__path
> FROM ent_categorie
> LEFT JOIN entada.ent_categorie AS fcat ON
> fcat.id=ent_categorie.categorie_id
>
> I've tried different ways using joinAdd(), selectAs(), selectAdd()
> but never achieved my goal


Hmmh, how about this one:

$do = DB_DataObject::factory('tableName');
$linkDo = DB_DataObject::factory('tableName');

$do->joinAdd($linkDo, 'LEFT', 'tableAlias');
$do->selectAs($linkDo, 'tableAlias_%s', 'tableAlias');

This seems to work here in a different context.

Cheers Jan
--
Jan Wagner <wagner@netsols.de>
netsols.de
arnaud sellenet

2006-08-23, 6:58 pm

Yes indeed... does the job, thanks so much !

Le 23 ao=FBt 06 =E0 10:48, Jan Wagner a =E9crit :

>
> Forgot a $do->selectAs() here.
>
>
> Jan
>
> --=20
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com