appeland Posted May 23, 2006 Share Posted May 23, 2006 Hello,this problem is described in a lot of forums and other articels on the net already but I still cant make it work:I am trying to put a class into a session so that I dont have toinclude it again and again (it's a DB Access Class).[b]Here is what I do on page one:[/b][code]<?include('database.php');session_start(); header("Cache-control: private"); //IE 6 Fix $_SESSION ['database'] = new database;$database = &New database;$query="SELECT name FROM users where id = 63";$database->setQuery($query);$row=$database->loadObjectList();$row=$row[0];?><a href ="http://testserver/test/test2.php">Show <? echo $row->name;?>'s username</a>[/code]-> this works fine and the result is delivered from the DB.[b]The link in there brings me to the next page which looks like this:[/b][code]<?session_start();header("Cache-control: private"); //IE 6 Fix echo "Session: <pre>";print_r($_SESSION);echo "</pre><br><br>"; $query="SELECT username FROM users where id = 63";$database->setQuery($query);$row=$database->loadObjectList();$row=$row[0];echo $row->username;?>[/code]As you can see I am looking into the session to see what's in it but I keep getting:[b][database] => __PHP_Incomplete_Class Object.[/b]All the topics I found somewhere else just say that I need to include the class file beforeI start the session, but I do that already [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /] I know this is trivial but I just cant get the hang of it.Your help is highly appreciated.Thanks & Regards,Andi Quote Link to comment Share on other sites More sharing options...
Barand Posted May 23, 2006 Share Posted May 23, 2006 Try this approach[code]<?php session_start(); if (isset($_SESSION['myobjectname'])) { $myobjectname= unserialize($_SESSION['myobjectname']); } else { $myobjectname= new myobjectname(); } // processing // resave $_SESSION['myobjectname'] = serialize ($myobjectname);?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.