Posted by Dikkie Dik on 12/06/05 00:37
That depends. If the instance is to be kept in one "build" of your page
(your different pages are included and/or required) you can keep it in a
(global) variable.
If it has to exist along mutiple client requests, it is another story.
HTTP is a stateless protocol, so once the page has been sent to the
client, all is over and forgotten. No state is kept.
Now this can be "repaired" with sessions if you use them. However, a
session is nothing more than a storage "just in case the client comes
back". Web applications lead a very fragmented life.
Especially a database connection is not something I would store between
sessions. There is a major chance that the client does not come back
(every website visitor leaves at SOME point) and you would end up
keeping connections open that are not used anymore.
If you do want an object stored in the session, just keep it in the
SESSION array (a superglobal). Beware that the classes have to be
defined (and timely) in every page that can encounter such an object.
Best regards
gachsaran wrote:
> Hi
>
> I have a class that is my interface to mysql. I create an instance og
> class an connect to db. Then i change to another page and want to use
> the same instace of class. How can i send an object (the instance) to
> another page ?
>
>
> Any help will be appricated.
> Gachsaran
[Back to original message]
|