I need to pass the PDO connection to the cart
class from controller
,
function __construct($connection) { $this->cart = new cart($connection); }
but I think the problem is serialize()
public function render_page() { if (!isset($_SESSION[SESSION_CART])) { $cart = $this->cart; } else { $cart = unserialize($_SESSION[SESSION_CART]); } $_SESSION[SESSION_CART] = serialize($cart); }
I get this error
Fatal error: throw a "PDOException" exception with the message "You cannot serialize or unesterialize PDO 'instances in C: \ WAMP \ WWW \ store_2012_MVC \ Local \ Controllers \ class_base_extended_cart.php: 89 Stack trace: # 0 [internal function]: PDO β __ sleep () # 1 C: \ WAMP \ WWW \ store_2012_MVC \ Local \ controllers \ class_base_extended_cart.php (89): serialize (object (cart)) # 2 C: \ WAMP \ WWW \ store_2012_MVC \ Local \ controllers \ class_factory .php (75): base_extended_cart-> render_page () # 3 C: \ wamp \ www \ store_2012_MVC \ index.php (69): factory β render () # 4 {main} thrown C: \ WAMP \ WWW \ store_2012_MVC \ Local \ controllers \ class_base_extended_cart.php on line 89
How can i fix this?
Or can I use something else instead of serialize()
?
EDIT:
I tried it with the magic methods __sleep
and __wakeup
, but still getting the same error,
class database_pdo {
source share