Bluehost.com Web Hosting $6.95

simple questions but please answer me

This is a discussion on simple questions but please answer me within the MySQL Database forums, part of the Database Forums category; Hi, I'm ending my website built with php+mysql. In a first moment I didn't want to use ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-01-2007
Mr.Orange
 
Posts: n/a
Default simple questions but please answer me

Hi,
I'm ending my website built with php+mysql.
In a first moment I didn't want to use mysql but with the help of some
manuals and 'how to' I have learned the most important instructions for
my necessities.
Only in few articles I have found annotations on the importance to close
the access to database after every login and interrogation.
In some cases I've found simply this line at the end of the php page:

mysql_close($db);

in other cases:

mysql_free_result($xx);
mysql_close($db);

in other cases any worry to close the access!

In my website every page connects to database, so please could you
explain me the importance to close the database connection for each page?

What are the correct istructions to follow at the end of a webpage to
correctly disconnect from a database?

I speak a little english, i hope that you understand what i need.
Thanks.

Marco (Italy)

Reply With Quote
  #2 (permalink)  
Old 02-01-2007
Captain Paralytic
 
Posts: n/a
Default Re: simple questions but please answer me

On 1 Feb, 10:53, "Mr.Orange" <freypnospa...@alice.it> wrote:
> Hi,
> I'm ending my website built with php+mysql.
> In a first moment I didn't want to use mysql but with the help of some
> manuals and 'how to' I have learned the most important instructions for
> my necessities.
> Only in few articles I have found annotations on the importance to close
> the access to database after every login and interrogation.
> In some cases I've found simply this line at the end of the php page:
>
> mysql_close($db);
>
> in other cases:
>
> mysql_free_result($xx);
> mysql_close($db);
>
> in other cases any worry to close the access!
>
> In my website every page connects to database, so please could you
> explain me the importance to close the database connection for each page?
>
> What are the correct istructions to follow at the end of a webpage to
> correctly disconnect from a database?
>
> I speak a little english, i hope that you understand what i need.
> Thanks.
>
> Marco (Italy)


A web page does not connect to a database. It is the php script that
is running on the server that does that.
As long as you are not opening persistent connections, the connection
will be closed when the current set of php scripts finishes executing,
so you do not need to worry about either mysql_free_result($xx);
mysql_close($db); at the end of the scripts.

Reply With Quote
  #3 (permalink)  
Old 02-02-2007
Mr.Orange
 
Posts: n/a
Default Re: simple questions but please answer me

Thank you for the answer.
My worry is that if I don't close the connection with an appropriate
command and there are more users simultaneously connected, there can be
a loss of performance or deceleration of the server.
I hope that you understand what I want to say.

Marco



> A web page does not connect to a database. It is the php script that
> is running on the server that does that.
> As long as you are not opening persistent connections, the connection
> will be closed when the current set of php scripts finishes executing,
> so you do not need to worry about either mysql_free_result($xx);
> mysql_close($db); at the end of the scripts.


Reply With Quote
  #4 (permalink)  
Old 02-02-2007
Captain Paralytic
 
Posts: n/a
Default Re: simple questions but please answer me

On 2 Feb, 11:51, "Mr.Orange" <freypnospa...@alice.it> wrote:
> Thank you for the answer.
> My worry is that if I don't close the connection with an appropriate
> command and there are more users simultaneously connected, there can be
> a loss of performance or deceleration of the server.
> I hope that you understand what I want to say.
>
> Marco
>
>
>
> > A web page does not connect to a database. It is the php script that
> > is running on the server that does that.
> > As long as you are not opening persistent connections, the connection
> > will be closed when the current set of php scripts finishes executing,
> > so you do not need to worry about either mysql_free_result($xx);
> > mysql_close($db); at the end of the scripts.- Hide quoted text -

>
> - Show quoted text -


Each "user" will be running a separate php session (not technically
the correct term, but it'll do for now). Unless you have specifically
opened persistent connections, each 'user' whole session (and their
connections) will be shut down when apache (or whatever other server
you are using) has finished delivering the page to the browser.

Reply With Quote
  #5 (permalink)  
Old 02-02-2007
Mr.Orange
 
Posts: n/a
Default Re: simple questions but please answer me

Perfect, is the answer I need.
Thanks and regards

Marco
Reply With Quote
  #6 (permalink)  
Old 02-02-2007
Jerry Stuckle
 
Posts: n/a
Default Re: simple questions but please answer me

Mr.Orange wrote:
> Hi,
> I'm ending my website built with php+mysql.
> In a first moment I didn't want to use mysql but with the help of some
> manuals and 'how to' I have learned the most important instructions for
> my necessities.
> Only in few articles I have found annotations on the importance to close
> the access to database after every login and interrogation.
> In some cases I've found simply this line at the end of the php page:
>
> mysql_close($db);
>
> in other cases:
>
> mysql_free_result($xx);
> mysql_close($db);
>
> in other cases any worry to close the access!
>
> In my website every page connects to database, so please could you
> explain me the importance to close the database connection for each page?
>
> What are the correct istructions to follow at the end of a webpage to
> correctly disconnect from a database?
>
> I speak a little english, i hope that you understand what i need.
> Thanks.
>
> Marco (Italy)
>


Although as others have indicated it's not necessary to close the
connection or free the result, I prefer to do it myself rather than let
the PHP interpreter do it. It may be a while before the interpreter
gets around to cleaning up after the script ends, especially in a
heavily loaded server (cleanup is generally not as important as
executing the scripts themselves).

I go by the rule that as soon as I'm done with a result, I free it. As
soon as I'm completely done with the connection on that page, I close it.

I find it's just generally a good programming practice to clean up after
myself rather than let the system do it for me.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #7 (permalink)  
Old 02-03-2007
Mr.Orange
 
Posts: n/a
Default Re: simple questions but please answer me

Hi Jerry,
and about the cleanup are enough these two lines to the end of each php
page:

mysql_free_result($xx);
mysql_close($db);


or there's some other command to add?

Thanks.
Marco


> Although as others have indicated it's not necessary to close the
> connection or free the result, I prefer to do it myself rather than let
> the PHP interpreter do it. It may be a while before the interpreter
> gets around to cleaning up after the script ends, especially in a
> heavily loaded server (cleanup is generally not as important as
> executing the scripts themselves).
>
> I go by the rule that as soon as I'm done with a result, I free it. As
> soon as I'm completely done with the connection on that page, I close it.
>
> I find it's just generally a good programming practice to clean up after
> myself rather than let the system do it for me.
>

Reply With Quote
  #8 (permalink)  
Old 02-03-2007
Jerry Stuckle
 
Posts: n/a
Default Re: simple questions but please answer me

Mr.Orange wrote:
> Hi Jerry,
> and about the cleanup are enough these two lines to the end of each php
> page:
>
> mysql_free_result($xx);
> mysql_close($db);
>
>
> or there's some other command to add?
>
> Thanks.
> Marco
>
>
>> Although as others have indicated it's not necessary to close the
>> connection or free the result, I prefer to do it myself rather than
>> let the PHP interpreter do it. It may be a while before the
>> interpreter gets around to cleaning up after the script ends,
>> especially in a heavily loaded server (cleanup is generally not as
>> important as executing the scripts themselves).
>>
>> I go by the rule that as soon as I'm done with a result, I free it.
>> As soon as I'm completely done with the connection on that page, I
>> close it.
>>
>> I find it's just generally a good programming practice to clean up
>> after myself rather than let the system do it for me.
>>


That's all you need. But I don't necessarily put them at the end of the
page. For instance, I free a result as soon as I'm done with it. So
once I fetch the data and use it, I free the result immediately. And
once I've completed my last request to the database, I close the
connection immediately.

Freeing the result immediately is more important, IMHO. Often times
I'll have a page which makes several separate requests to MySQL.
Freeing a result as soon as I'm done with it means I'm not unnecessarily
tying up MySQL and other system resources. It's also easier to remember
to free it if you're doing it right where you 're using the result set.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #9 (permalink)  
Old 02-03-2007
Mr.Orange
 
Posts: n/a
Default Re: simple questions but please answer me

> Jerry Stuckle ha scritto:
> That's all you need. But I don't necessarily put them at the end of the
> page. For instance, I free a result as soon as I'm done with it. So
> once I fetch the data and use it, I free the result immediately. And
> once I've completed my last request to the database, I close the
> connection immediately.


ok, thanks to you too.
;-)

Marco



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:30 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0