I have been faced a couple of times with the situation that I wanted to
write a script and was worried about a too frequent opening and closing
mysql connections.
To give some examples:
1)I am trying to develop a photoalbum (also posted a topic called "array /
mysql question"). Of course I can use some wonderful open source albums but
at the same time I want to get more familiar with all the ins and outs so my
idea is a list of filenames, where the database connection should be
opened, a statement like"select filenames from photos" , and, every filename
maybe with a thumbnail is a link to a second page and the whole is followed
by closing the connection. The second page could be something like opening
the database connection, a statement like "select description ( and other
fields) from photos where filename = $filename" , and closing the database
again. Let's say the visitor looks at the picture and its description,
clicks on a link to the first page with the thumbnails and agin the
connection is opened and closed to execute the first select statement, the
visitor chooses another picture etc. etc....
2)On www.tapperijbeekendonk.nl on the left column there is a menu item
"activiteiten". when there are special activities like a music performancein
the near future they are shown below that menu item. A select statement is
done where the first announcement date, and the last announcement date are
checked and the records where the current date is between those values are
selected (and shown in the menu bar of course). Again the connection is
opened and closed again immediately after the select statement. However,
this query is stored in "header.php" so on every page that is visited, the
connection is opened and closed. It would also be nice to make a link on the
"one-photo-page" to the previous and the next photo, which leads again to
the open-select-close "ritual".
I am not really a php guru (but not a newbie either) and unfortunately I
could not find many info on google about the performance issues that can be
involved when I decide to write such scripts. There were some vague
indications that it is better to open and close a connection frequently than
leave it open too long in order to execute more queries but I could not
really find good documentation about it.
I also thought to store the results of the query into a session variable but
I am not sure about the performance issues of sessions either.
Any ideas will be welcome.
Thanks,
Martien.