Re: A couple of questions...
| From: | php3 at developersdesk dot com | Date: | Fri, 24 Nov 2000 11:11:05 +0000 |
| Subject: | Re: A couple of questions... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-26922@lists.php.net to get a copy of this message | ||
Addressed to: =?iso-8859-1?Q?Daniel_Als=E9n?= <daniel@innehallsbolaget.com>
php-general@lists.php.net
** Reply to note from =?iso-8859-1?Q?Daniel_Als=E9n?= <daniel@innehallsbolaget.com> Fri, 24
Nov 2000 10:20:47 +0100
>
> Hi guys - a couple of questions:
>
> - When working with MySQL. Should i close the connection at the end of
> the code of every question to the database (mysql_close)? Is there an
> uneccessary load on the server if i don t?
>
NO!
Opening the connection is often the biggest delay in using a database.
If you do only one query per page, there is no reason to close anything at
all. PHP will do it for you when the script ends. PHP is very good at
garbage collection.
If you do many queries in one script, it is wise to use mysql_free_result(
$Result ) when you are done with each result set to save memory. (Except
the last, which will be closed by PHP as soon as the script ends.)
If you don't open too many different databases from your web server you
might want to use persistant connections to reduce the number of connects
even more. mysql_pconnect() (I think.) I do run a large number virtual
domains on a single server, so I don't use it. Eventually you end up
trying to open Num_virtual_hosts * Num_Apache_Threads connections. Usually
the database server runs out of connections and things fail.
> - What methods should i use to speed up database searches? Is there
> anything more i can do excepts from indexing the fields im using for the
> search?
Try your queries from the command line interpreter, and use EXPLAIN.
http://www.mysql.com/documentation/mysql/commented/manual.php?section=EXPLAIN
> - How do i easily decide in what order listing of a table is returned?
ORDER BY in the query.
If you haven't yet, you should look over the MySQL manual. Section 7, the
command reference, is very important to know your way around. MySQL can do
quite a bit for you before the data is passed to PHP.
Rick Widmer
Internet Marketing Specialists
www.developersdesk.com
When all you have is a hammer,
everything looks like a nail.