Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

In Drupal 7, for some reason, i am storing some serialize($node) objects into Database. So these data in the database (in text column) are storing like:

O:8:"stdClass":47:{s:3:"vid";s:5:"78629";s:3:"uid";s:3:"523";s:5:"title";s:12:"Sync Node #6";s:6:"status";i:1;s:3:"nid";s:5:"77429";s:4:"type";s:4:"page";s:8:"language"; ..... etc
  • Now how can i transform these data back into Drupal $node Object please?
  • Then how can i node_save($node) (as new node) upon them? (What tricks will i need?)

Any idea please?

share|improve this question

2 Answers

Now how can i transform these data back into Drupal $node Object please?

As said you can use the following code,

$node = unserialize($data);

Then how can i node_save($node) (as new node) upon them? (What tricks will i need?)

You can null the nid, vid and use node_save to save it as a new node like this:

$node->nid = NULL;
$node->vid = NULL;
node_save($node);
share|improve this answer

Call unserialize() on the serialized data.

share|improve this answer
Hmmm.. Then how please? – 夏期劇場 Oct 15 '12 at 6:48
Like so: $node = unserialize($data); where $data is the string that is stored in the database. – Oswald Oct 15 '12 at 6:50
But, i mean .. i can NOT node_save($node) it :/ (Then how can i node_save($node) (as new node) upon them? (What tricks will i need?)) – 夏期劇場 Oct 15 '12 at 6:55
The node already has a nid and a vid. Upon saving, node 5 is updated. Call unset($node->nid); to remove the nid before saving it to create a new node. – Oswald Oct 15 '12 at 7:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.