phpgroupware-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fwd: SV: [Phpgroupware-developers] php5 vs php4: db-handling]


From: Chris Weiss
Subject: Re: [Fwd: SV: [Phpgroupware-developers] php5 vs php4: db-handling]
Date: Sun, 29 Jan 2006 23:12:47 +0000

the idea behind having a global db object was that you only have to do
the login process once, and then your classes can make a copy of that
global when your app logic needs 2 separate result objects,  which
happens much faster then creating a new instance.

the "right" way for php 4 and 5 support in our current db class would
be to bring in pear's php_compat::clone() for php4 and use $this->db  
= clone($GLOBALS['phpgw']->db); when we want a copy.  this has the
added benefit that we can add a __clone() method to the db class and
make sure any result resources are not copied because that's rarely
wanted.  If we are going to add a new function, this is the way we
should go because it will mean a performance boost for php5 and not
the "hobbled compatibility" madness we suffer now from our
not-fully-removed php3 and php4.0.x compat code.

or just start using adodb instead where the main connection is always
shared and the results are all their own objects, which makes a hell
of a lot more sense anyway.  let adodb worry about php4|5 and let us
just get work done.



On 1/29/06, Sigurd Nes <address@hidden> wrote:
> Kai Hofmann wrote:
> > address@hidden schrieb am 29.01.06 12:53:45:
> >
> >>
> >> -------- Original-Nachricht --------
> >> Betreff: SV: [Phpgroupware-developers] php5 vs php4: db-handling
> >> Datum: Sun, 29 Jan 2006 00:03:37 +0100 (CET)
> >> Von: Sigurd Nes <address@hidden>
> >>
> >
> >
> >>>> It seems like php5 differ from php4 when one needs a second db-object
> >>>> inside a db->next_record()-loop.
> >>>>
> >>>> In php4 one can do like this:
> >>>>
> >>>> $this->db  = $GLOBALS['phpgw']->db;
> >>>>
> >>>> $this->db2 = $this->db;
> >>>>
> >>>>
> >>>> While for php5 one has to alter to:
> >>>>
> >>>> $this->db            = $GLOBALS['phpgw']->db;
> >>>> $this->db2           = CreateObject('phpgwapi.db');
> >>>> $this->db2->Host     = $GLOBALS['phpgw_info']['server']['db_host'];
> >>>> $this->db2->Type     = $GLOBALS['phpgw_info']['server']['db_type'];
> >>>> $this->db2->Database = $GLOBALS['phpgw_info']['server']['db_name'];
> >>>> $this->db2->User     = $GLOBALS['phpgw_info']['server']['db_user'];
> >>>> $this->db2->Password = $GLOBALS['phpgw_info']['server']['db_pass'];
> >>>>
> >>>> The db initialization could be moved to a function to enable this:
> >>>> $this->db2 = $GLOBALS['phpgw']->new_db;
> >>>>
> >>>> Any thoughts?
> >>>>
> >>>>
> >>> <excerpt cite="http://www.zend.com/php5/andi-book-excerpt.php";>
> >>> In PHP 5, the infrastructure of the object model was rewritten to work
> >>> with object handles. Unless you explicitly clone an object by using the
> >>> clone  keyword you will never create behind the scene duplicates of
> >>> your objects. In PHP 5, there is neither a need to pass objects by
> >>> reference nor assigning them by reference. </excerpt>
> >>>
> >>> HTH,
> >>> Earnie Boyd
> >>>
> >>>
> >> Could you make an example of the db-class, and relate it to how it is
> >> used trough out phpgroupware?
> >> I have now in the app 'property' switched to initialize the db-classes
> >> with a function new_db() - and it works fine with both php4 and php5.
> >> (But of course - ther could be smarter ways...)
> >>
> >
> >
> > I have fixed this already within the probusines groupware ;-)
> > Could be simply fixed by doing this:
> >
> >                       // $db2 = $this->db;
> >                       $db2 = CreateObject('phpgwapi.db');
> >                       $db2->Type     = $this->db->Type;
> >                       $db2->Host     = $this->db->Host;
> >                       $db2->Database = $this->db->Database;
> >                       $db2->User     = $this->db->User;
> >                       $db2->Password = $this->db->Password;
> >                       $db2->connect();
> >
> >
> > Greetings
> >
> >    PowerStat
> > _______________________________________________________________________
> Thanks for the feedback - I propose a new function in class.common.inc.php
>
>         function new_db()
>         {
>             $db = CreateObject('phpgwapi.db');
>             $db->Host = $GLOBALS['phpgw_info']['server']['db_host'];
>             $db->Type = $GLOBALS['phpgw_info']['server']['db_type'];
>             $db->Database = $GLOBALS['phpgw_info']['server']['db_name'];
>             $db->User = $GLOBALS['phpgw_info']['server']['db_user'];
>             $db->Password = $GLOBALS['phpgw_info']['server']['db_pass'];
>             return $db;
>         }
>
> And to initialize new db-objects like this:
>    $this->db     = $GLOBALS['phpgw']->common->new_db();
>    $this->db2   = $GLOBALS['phpgw']->common->new_db();
>
> Regards
>
> Sigurd
>
>
> _______________________________________________
> Phpgroupware-developers mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/phpgroupware-developers
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]