Re: Should I use destructor to save object back to DB?
| From: | Mike Zornek | Date: | Wed, 07 Apr 2004 18:33:27 +0000 |
| Subject: | Re: Should I use destructor to save object back to DB? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-11725@lists.php.net to get a copy of this message | ||
On 4/5/04 4:32 PM, "Tim Lieberman" <emci@speakeasy.org> wrote:
> Call saveToDB() manually, and do it every time.
>
> The main reason to do this is sometimes you don't want changes to
> go to the database. This might be due to an error condition, for
> example.
>
> While updating the database automagically seems attractive, my
> intuition is that you'll start running into special cases. It'll be a tough
> sort of "feature" to remove, because you'll need to audit your whole
> app and find all the places that saveToDB() needs to be called.
I'm starting to agree that this is the way to go. How about DB
disconnections? I'm basically connecting in the constructor and would like
to disconnect in the destructor to save some overhead of connecting and
disconnecting in particular methods.
Can the destructor be trusted to disconnect. I suppose worst case is that
I'll run out of connections if something bad happens .. But I think I would
find this fast with testing/benchmarks on the code.
~ Mike
-----
Mike Zornek
Web Designer, Media Developer, Programmer and Geek
Personal site: <http://MikeZornek.com>
New Project: <http://WebDevWiki.com>