Re: Re: Create collections of objects

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

 



Emilio Astarita wrote:
> Peter Ford <pete@xxxxxxxxxxxxx> writes:
> 
>> Emilio Astarita wrote:
>>> Hi people,
>>>
>> A static method should still be able to set values of private members. I do
>> something like:
>> ...
>>
> 
> Thank you, I was not sure how to implement it.
> 
> Another question. It would be a better approach, making the constructor
> private?

Maybe: I use the constructor in other places, so in my case, no.
> 
>> Then you get an array of elements which match the (possibly wild-carded)
>> condition, indexed by the element Id (useful for making HTML <select> lists, for
>> example).
>>
>> In fact, I have a base class which implements this by class introspection -
>> filling the properties of objects which extend it by mapping them to the
>> database fields...
>>
> 
> Good idea. Do you use a script to do mapping or you ask by the fields
> to the database with the name of the table?
> 
> Thanks again
> 

I have the classes which extend my BaseData class provide the SQL statement they
will use (or at least the bit between 'SELECT' and 'WHERE'), and also an array
of database field -> class property mappings.

This is really overkill, since you can use something like "SELECT foo AS id, bar
AS name ..." to do the mapping to field names directly from the SQL.

Letting the Element class define the SQL to get itself also lets you do some
processing of the database, such as using JOINS across tables, COALESCE to
provide default values where NULL is stored, and all sorts of useful database
tricks. That makes the database share the work and cuts out some of the PHP
processing...

-- 
Peter Ford                              phone: 01580 893333
Developer                               fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux