[solved] (un)serialize()
Posted: Wed Dec 20, 2006 11:27 pm
I'm having problems unserializing() a string I've got. The string in the database looks like so:
When I retrieve that string from the DB & unserialize it, the resulting array is empty - in fact it doesn't even exist. Outputing the results of unserialize() get me nothing.
However, when I take that string & store it just as a string, throw it in an array, serialize() it, & unserialize() it, everything looks ok.
So, unserializing is only giving me a problem when I'm pulling the string out of the database. However, outputing the result of mysql_fetch_assoc() yields me the serialized array, with the table embedded inside it.
Please tell me I'm missing something painfully obvious.
FYI: the code I'm using to pull the data out of the db is:
- $this->DB is my mysql-wrapper object
- $this->DB->execute() is a wrapper for mysql_query();
- $this->DB->getData() is a wrapper for mysql_fetch_assoc();
Code: Select all
a:1:{s:8:"contents";s:392:"<table width="200" cellspacing="1" cellpadding="1" border="1" align="" summary="">
<tbody>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>";}However, when I take that string & store it just as a string, throw it in an array, serialize() it, & unserialize() it, everything looks ok.
So, unserializing is only giving me a problem when I'm pulling the string out of the database. However, outputing the result of mysql_fetch_assoc() yields me the serialized array, with the table embedded inside it.
Please tell me I'm missing something painfully obvious.
FYI: the code I'm using to pull the data out of the db is:
Code: Select all
$query = <<<SQL
SELECT
*
FROM
pages
WHERE
id = '$this->page_id'
SQL;
$result = $this->DB->execute($query,'retrieving page properties');
$row = $this->DB->getData($result);
$this->contents = unserialize($row['contents']);- $this->DB->execute() is a wrapper for mysql_query();
- $this->DB->getData() is a wrapper for mysql_fetch_assoc();