Re: MySQL close connection, what's the purpose?

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

 



On 4/2/06, tedd <tedd@xxxxxxxxxxxx> wrote:
> >  > > > I always close the connection right after my
> >>  > > query -- force of habit. It's like leaving the
> >>  > > toilet seat up, it's only going to get you into
> >>  > > trouble.
> >>  >
> >>  > So you close it after every query and then re-open it later for the
> >>  > next query? I don't see that as a good idea.
> >  > >
> >  > No, you leave it open until you're done with the database.
> >
> >Reading Ted's post didn't give this impression. I wanted to make sure
> >he wasn't doing it that way.

Firstly sorry for calling you Ted, not Tedd :)

> Actually I am. When I need something from the dB, I open it, get the
> information and close it. It's like opening a drawer, getting what
> you need, and then closing the drawer. Where's the problem?
>
> I don't see any reason whatsoever for me to open the dB at the start
> of my session and then close it at the end. Is there some
> overwhelming reason for anyone to do so?

Time. Opening a db connection is time consuming. There are many levels
involved (making the connection, authentication, etc).. Even worse if
the connection is over tcp/ip because that overhead comes in on top as
well.

> You see, my habit stems from doing a lot of communication programming
> -- it was my experience that you open a communication port
> (file/channel/port/whatever); establish a link; exchange data; and
> close it. There's no need to leave it open.

Just because you can close it doesn't mean you have to.

You can send 10 (or 100) messages through an smtp server before closing it...

It depends on what you are doing.

I'm sure there are tons of cases where you should open/action/close.
Db isn't one of those.

--
Postgresql & php tutorials
http://www.designmagick.com/

-- 
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