-1

i am trying to unserialize string that is stored in mysql table.

following is the string stored in mysql table.

a:3:{s:15:\"purchase_amount\";d:500;s:4:\"more\";d:7;s:4:\"less\";d:11.5;}

at the time of insertion i had written following code.

addslashes(serialize(array('purchase_amount' => $values['purchase_amount'], 'more' => $values['transportaion_cost_gretter'], 'less' => $values['transportaion_cost_lesser'])))

At retrieval i had written followin code.

unserialize(stripslashes($row->getTransportaionCost()));

i am getting following error.

Notice: unserialize() [function.unserialize]: Error at offset 5 of 98 bytes 

EDIT:

i tried json_encode and json_decode...

following is json data in mysql table

{"purchase_amount":500,"more":7,"less":11.5}

Following is the json decode in php.

var_dump(json_decode($row->getTransportaionCost())); //null

can any one tell me what is the problem ?

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
hardik
  • 9,141
  • 7
  • 32
  • 48

1 Answers1

0

The problem comes from when you store your data in the database, those antislashes shouldn't be here. Remove the addslashes, it will work better

Ugo Méda
  • 1,205
  • 8
  • 23