views:

45

answers:

1

Hi guys I'm in an emergency here. My code was working FINE for a while when ALL of a sudden somethings gone wrong and I havent a clue what! I store an object in my database by serializing it and then running a base64_encode on it. The result is an encoded serialised string which when I wish to retrieve I just decode and unserialise it.

Its been working fine but all of a sudden I have no idea why - whenever I try to run the part which does the insertion - it encodes the object corrrectly but after running the sql query - the value which ends up in the database is a truncated mess!!!!

Its not a database issue for if I manually copy paste the encoded string in the field it copies and is inserted fine.

I have no idea whats going on - the code below is how I'm making the update:

$personsTable = new ZFltData_Db_Table(array('name'=>'people'));
$where = $personsTable->getAdapter()->quoteInto('id = ?', $id);
$data['object'] = base64_encode(serialize($obj));
$personsTable->update($data, $where);

The database field is actually a longText.

EDIT ==== Sorry bout that. Well the encrypted string looks like this:

YToyOntpOjA7YTozOntzOjg6ImNhdGVnb3J5IjtzOjU6InBob25lIjtzOjQ6InR5cGUiO3M6NDoiV29yayI7czo3OiJkZXRhaWxzIjtzOjEzOiIxMjMzIDQzNTQzNTQ1Ijt9aToxO2E6Mzp7czo4OiJjYXRlZ29yeSI7czo1OiJwaG9uZSI7czo0OiJ0eXBlIjtzOjQ6IkhvbWUiO3M6NzoiZGV0YWlscyI7czoxNzoiMTAwOTEyIDgwOTgxMjkwMTIiO319

It loks that way if I manually copy paste it into the database using Navicat explorer.

However the code when executes ends up putting just the following in the database:

Tjs=

Weird part is that this is all that is entered no matter what the contents of the object encoded...the object is actually an associative array... whats wrong here? It was working fine until... just today...

+3  A: 

Tjs= base64_decodes to N;, which is the serialized representation of null.

So, $obj is null in your script at the point you serialize it, and not an associative array.

It's impossible to tell why that is, because we don't know where $obj comes from. If it's something you are working with further up in your script, make print_r() tests to see whether it gets overwritten somewhere.

Pekka
+1 Nice deduction!
fireeyedboy
Good point let me check and I'll let you know in a minute!
Ali
By Jove you were right! Thanks a bunch man - I was calling the update query twice - the first time it would be passed the object whilst the second time a null - thanks alot man you saved me a whole afternoon of debugging :D
Ali