Page 1 of 1
class w/ database handler to otehr docs
Posted: Tue Sep 03, 2002 2:19 pm
by PingLeeQuan
Hello... I have a class that connects to a database and opens it. The class is "require" in my index.php
What i am trying to do is use the "handler" ( the connection to the database that i have in index.php) in another document called, getdata.php where i actually need to READ the tables and fetch the result.
I know i can access regular variables through $_POST... and/or $linkid....
Does this apply also to what i am trying to do? or do i need to establish teh connection again?
thanks in advance
Posted: Tue Sep 03, 2002 3:07 pm
by JPlush76
you have to have that class include file in the other document as well
so if you include the database class file in index.php you have to also include it to the other pages that will be using the database connection.
Posted: Tue Sep 03, 2002 3:22 pm
by PingLeeQuan
wouldn't that reinstanciate my class again? I am trying to have 1 instanciation per session.
thanks jim
Posted: Tue Sep 03, 2002 5:12 pm
by samscripts
Hi,you need to re-connect to the database in every script.
ie. every time someone browses a page on your site that accesses the database, that script needs to open a new connection.
I am trying to have 1 instanciation per session
do you mean each visitor to your site has only one database connection made, and you would store this in the session variable? This won't work, and would be a waste of resources as well, even if you could do it.
just include the connection class (include() or require()) in each script you need the database connection in.
hope this helps, Sam
Posted: Tue Sep 03, 2002 9:06 pm
by nielsene
Class objects, by default, can not be passed between pages using session variables. If you provide the __sleep and __wake magic functions, then the class can be serialized across the session. However. even with serialization its a very bad idea to store the database connection and it won't work. You could, however, write your __wake function to re-establish the db conenction on deserialization so it appears transparent.
Persistent Database Connection
Posted: Wed Sep 04, 2002 12:27 am
by gite_ashish
Posted: Wed Sep 04, 2002 7:54 am
by PingLeeQuan
Thanks guys... that helped greatly...
