This is a discussion on connection from one page to another within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi I have a class that is my interface to mysql. I create an instance og class an connect to ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
If you store an object in session it will be serialized and you "keep"
the same instance. But the database connection will be lost. When the script exits at the end of the page it will clean up resources that are not needed any more. Since HTTP is a stateless protocol you don't know if the next page will open or not. What you might want in your database class is something like: public static function query ($qString) { if (!self::$dbConn) { // If no SQL connection is established self::connect(); } | A static class can also be useful since you (most likely) only use one instance of the object. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|