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
class w/ database handler to otehr docs
Moderator: General Moderators
-
PingLeeQuan
- Forum Commoner
- Posts: 58
- Joined: Tue Sep 03, 2002 8:08 am
-
PingLeeQuan
- Forum Commoner
- Posts: 58
- Joined: Tue Sep 03, 2002 8:08 am
-
samscripts
- Forum Commoner
- Posts: 57
- Joined: Tue Apr 23, 2002 4:34 pm
- Location: London, UK
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.
just include the connection class (include() or require()) in each script you need the database connection in.
hope this helps, Sam
ie. every time someone browses a page on your site that accesses the database, that script needs to open a new connection.
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.I am trying to have 1 instanciation per session
just include the connection class (include() or require()) in each script you need the database connection in.
hope this helps, Sam
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.
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
-
PingLeeQuan
- Forum Commoner
- Posts: 58
- Joined: Tue Sep 03, 2002 8:08 am