Storing class object

enouwee

Non ex transverso sed deorsum
Reaction score
240
With PHP, is there a way to store a class instance in a MySQL database?

Use serialize() and deserialize(). They don't work resources, like file descriptors or similar types. Storing such things in a database isn't a great idea thou.

PHP:
<?php

class Test
{
  function __construct($a, $b)
  {
        $this->a = $a;
        $this->b = $b;

  }

  private $a;
  private $b;
}

$t = new Test(1, 2);

print_r($t);
print_r(unserialize(serialize($t)));

?>

Outputs:

Code:
Test Object
(
    [a:private] => 1
    [b:private] => 2
)
Test Object
(
    [a:private] => 1
    [b:private] => 2
)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top