RE: [PHP-DB] cleaning up my connection act
| From: | John Bateman | Date: | Thu, 26 Oct 2000 19:01:01 +0000 |
| Subject: | RE: [PHP-DB] cleaning up my connection act | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-3969@lists.php.net to get a copy of this message | ||
Hi
The connections are usually closed at the end of the script UNLESS you are
using a persistent connection(). I would close them when I am done with them
though as this totally ensure that only resources needed are used. If script
XYZ has a connection open 3 seconds longer than it should is not big deal,
unless, you have 100's of instances of that script running.
If you need to use the results from one query in the where clause of another
query you can store the original query results into Object or array. Then
loop through the array while executing that second query. This allows you to
get the results you need with out over taxing your DB.
It's most important to realize that you really only need to use multiple
connection if the original query HAS to be open, I.E. if you are doing
something that uses an update sensitive recordset. (which incidentally I
don't believe exists in PHP).
My rule of thumb, if it isn't needed, close it down.
Hope this helps ya out.
> -----Original Message-----
> From: Larry Linthicum [mailto:webmaster@RetrieverSports.net]
> Sent: Thursday, October 26, 2000 11:42 AM
> To: php-db@lists.php.net
> Subject: [PHP-DB] cleaning up my connection act
>
>
> Hi, as my first ever attempt at programming I now have a
> website "working"
> using PHP and MySQL to produce a lot of dynamic content.
>
> My next step is to try and go back, and make the code a
> little cleaner.
>
> I have never understood ( still don't) the connection(s) to
> the database
>
> 1) should each one be closed ' mysql_close() ' as soon as it
> has served its
> need, or do they automatically close at the end of a script?
> ( I worry about
> overtaxing the server and I really have ZERO idea of how it all works)
>
> 2) If I want to make several queries to produce a page, say
> one as the page
> starts loading to get data that is used in the WHERE clause
> of another at
> the bottom of a page, to different tables in the same
> database. Do I need
> to open separate connections for each one? (the PHP is in
> separate blocks
> with straight HTML in-between, if that matters)
>
> anyway I haven't been able to find any documentation I could
> UNDERSTAND <G>
> on connections and how best to use them to not tax the system
> more than
> necessary and would appreciate info on that
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail:
> php-list-admin@lists.php.net