I've made a test script to try putting a serialized object into an SQL database, and then pulling it back out. The object is first stored serialized into a session variable, unserialized and displayed in a form, re-serialized and sent via session to another form, where it is put, serialized, into a hidden control that form. Then it is sent by POST to this script, which stores, then gets, the object from an sql database.
Here is where it is stored into the DB. (The ObjectString is coming from a hidden control on another page, it is the serialized string of the object)
$conn = new mysqli("localhost", "root", "----", "test");
$query = "INSERT INTO object (Object) VALUES ('{$_POST['ObjectString']}')";
$result = $conn->query($query);
Here is where it is pulled from the DB:
$query = "SELECT * FROM object";
$result = $conn->query($query);
$row_data = $result->fetch_array(1);
$obj = unserialize($row_data['Object']);
echo "phone" . $obj->phone;
When I try and run this, it gives me two errors:
Notice: unserialize() [function.unserialize]: Error at offset 0 of 4 bytes in ...
Notice: Trying to get property of non-object in ... on line 32
The second is of course because the object is not being unserialized.
Any ideas why this is happening? My SQL table only has one column, named Object, and is a text data type.
Any responses would be greatly appreciated!