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

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

 



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

Chris et al:

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?

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.

Additionally, isn't that they way the net is set up? When your browser accesses a web site, the browser sends a request for information, the web site responds, and then both of you attend to your own business. There is no maintaining an open communication link, other than a session or cookie.

Plus, if you are talking to several devices (including dB's) at once, then how do you know for sure which device you're talking to IF you leave all communication ports open?

Furthermore, from a code perspective, I always comment my open and close dB-includes as a pair -- like braces in a function or in an "if statement". That way, I always know where in my code are the dB segments. Additionally, I also number the error statements in the die portion -- so if something goes wrong, I know exactly where it went wrong.

This does not mean that I place an open/extract-insert/close dB within a loop. If I need to get something that way, then I open the dB before the loop and close the dB after the loop. However, I much prefer having MySQL do the looping for me.

It's my understanding that opening a dB isn't problematic and isn't something that I should worry about, right? It's also my understanding that opening a dB is very fast, and it can manage a large number of commands, and different connections very quickly, right? Then what's the problem with opening it several times during a session instead just once?

If someone cares to enlighten me with a convincing argument to do otherwise, I'll certainly consider and adapt. But my guess is, that opening a dB the way I do it presents no significant downside.

I've never had a problem with showing my ignorance before, so prove me wrong if you can. I can learn.

Thanks.

tedd
--
--------------------------------------------------------------------------------
http://sperling.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