PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am trying to save an MDB2 prepared statement so that I can reuse it for subsequent requests during a session. But I get the error:
Fatal error: logSqlUpdate(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "MDB2_Statement_mysql" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in /home/jcobban/includes/legacy.inc on line 619
It looks like the $connection->prepare() method returns an object. When you save an object as a session variable, it gets serialized, and when you retrieve it, it gets unserialized. The serialization stores the class of the object, and when it unserializes it, it reinstantiates the object with that saved class. You're getting that error because you aren't including the file with the class definition for whatever type of object $connection->prepare() returns, or you may be including it, but after you try to run the execute() method on the object recalled from the session variable.
jraede wrote:It looks like the $connection->prepare() method returns an object. When you save an object as a session variable, it gets serialized, and when you retrieve it, it gets unserialized. The serialization stores the class of the object, and when it unserializes it, it reinstantiates the object with that saved class. You're getting that error because you aren't including the file with the class definition for whatever type of object $connection->prepare() returns, or you may be including it, but after you try to run the execute() method on the object recalled from the session variable.
Thank you. To get around this, I just had to store the reference to the prepared statement instead of the prepared statement itself.