I want to uapdate a table field with an array.That means i have a table with name test.In that table i inserted some rows first.
After some process i want to update a filed in this table with ana array value.When i inserting rows into this table at that time this filed is set to 0.
After some process some values returned to a variable $var like:
Array
(
[id] => "http://www.google.com/calendar/"
[etag] => "GEwNTgxHfip7JGA6WhJV"
[link] => "http://www.google.com/calendar/"
)
This is the code iam using for updating field:
$idg= json_encode($var);
mysql_query("UPDATE `test` SET `tk` = '$idg' WHERE `TID` =10");
The above code is the edited code .The $idg now have:
{"id":"http:\/\/www.google.com\/calendar\/feeds\/testid%40gmail.com\/events\/64h9vc0qqqtlqeqhudhhdqbsds","etag":"\"GEwCQwxGeSp7JGA6WhJV\"\r","link":"http:\/\/www.google.com\/calendar\/feeds\/testid%40gmail.com\/private\/full\/64h9vc0qqqtlqeqhudhhdqbsds\r"}
After excuting this code the field will updated with null value.This is the problem facing now.
Since your table column can only contain a scalar value you have to convert the array into some string representation, e.g. via json_encode().
When you fetch the value from the table again you have to convert it back, in this case via json_decode().
edit: or use a storage mechanism/database that can handle this type of data, e.g. a document based database like mongodb.
edit2: add parameter encoding, error handling and debug code