Jump to content


Photo

__PHP_Incomplete_Class Object *gargel*


  • Please log in to reply
1 reply to this topic

#1 appeland

appeland
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 23 May 2006 - 11:38 AM

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 to
include it again and again (it's a DB Access Class).

Here is what I do on page one:
<?
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>

-> this works fine and the result is delivered from the DB.

The link in there brings me to the next page which looks like this:

<?
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;
?>

As you can see I am looking into the session to see what's in it
but I keep getting:

[database] => __PHP_Incomplete_Class Object.

All the topics I found somewhere else just say that I need to include the class file before
I 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


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 23 May 2006 - 06:39 PM

Try this approach
<?php
               session_start();

        if (isset($_SESSION['myobjectname'])) {
            $myobjectname= unserialize($_SESSION['myobjectname']);
        }
        else {     
            $myobjectname= new myobjectname();
        }

           // processing

          // resave  
          $_SESSION['myobjectname'] = serialize ($myobjectname);
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users