RE: object persistence within a session

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

 



> -----Original Message-----
> From: Andrew Ballard [mailto:aballard@xxxxxxxxx]
> Sent: Monday, November 10, 2008 8:04 AM
> To: ceo@xxxxxxxxx
> Cc: php-general@xxxxxxxxxxxxx
> Subject: Re:  object persistence within a session
> 
> On Mon, Nov 10, 2008 at 8:55 AM,  <ceo@xxxxxxxxx> wrote:
> >
> >> I've found that I don't mind a few well organized database calls per
> >> page for the information I need.
> >
> > Opening up a database connection is very expensive.
> >
> > Sending one more simple / fast query is dirt cheap.
> >
> > Time it on your system with http://php.net/microtime and see.
> >
> >
> 
> Perhaps, but the examples I usually find when cleaning up code are of
> the variety where a script executes one statement to find a list of
> parent records, iterates through those records and inside the loop it
> executes another statement (sometimes multiple statements!) to get the
> details, update records, etc.

>From strictly a coder's standpoint, I'm sure this helps view and understand source in an efficient manner. However, I think that you should always try to condense stuff like that into a JOIN query. Logically, it makes tons more sense to me to do that in SQL rather than PHP, since that's the sort of thing SQL was constructed to do in the first place (the "R" in RDBMS).

I find often that web programmers try to accomplish recursive database manipulation with multiple calls/connections to the database server in PHP rather than taking the time to structure a proper SQL query that will do the job and return all of the necessary data in one fell swoop.

Just my 2c. As always, if scale is not a concern, then you have quite a bit more breathing room to work with your chosen methods. I just analogize it with people doing complex DOM traversals and such when they could use 2 lines of standard CSS to get the job done...


Todd Boyd
Web Programmer


[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