serialize() problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
highway7
Forum Newbie
Posts: 5
Joined: Sat Apr 11, 2009 3:21 pm

serialize() problem

Post 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
User avatar
F00Baron
Forum Newbie
Posts: 6
Joined: Sat Feb 20, 2010 11:43 am

Re: serialize() problem

Post by F00Baron »

Try adding slashes.

Code: Select all

$serialized_xer = mysql_real_escape_string(serialize($album_array));
highway7
Forum Newbie
Posts: 5
Joined: Sat Apr 11, 2009 3:21 pm

Re: serialize() problem

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: serialize() problem

Post by pickle »

Output the query right before you execute it - make sure it's what you're expecting.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply