Page 1 of 1

serialize() problem

Posted: Fri Feb 19, 2010 5:17 am
by highway7
Hi,

I am trying to insert an array into a mySQL database using the serialize function. When I echo the function onto the page it works and I get this:

Code: Select all

a:1:{i:0;s:3:"111";}
However, when I insert this exact same variable into my dabase, it becomes null and I get this:

Code: Select all

a:1:{i:0;N;}
I am using wordpress and this is my code:

Code: Select all

$serialized_xer = serialize($album_array);
      echo $serialized_xer;
      $wpdb->query("UPDATE $wpdb->nggalbum SET sortorder = '$serialized_xer' WHERE id = '$album_id' ");
All help is greatly appreciated.

Thanks

Re: serialize() problem

Posted: Sat Feb 20, 2010 12:09 pm
by F00Baron
Try adding slashes.

Code: Select all

$serialized_xer = mysql_real_escape_string(serialize($album_array));

Re: serialize() problem

Posted: Mon Feb 22, 2010 10:21 am
by highway7
Ive tried both of those already with no luck.

Any ideas anyone please?

Could it be something to do with the fact that I need to create a class?

Re: serialize() problem

Posted: Mon Feb 22, 2010 12:15 pm
by pickle
Output the query right before you execute it - make sure it's what you're expecting.