Welcome Guest, Not a member yet? Register   Sign In
Saving an Array to Database
#4

[eluser]GrahamDj28[/eluser]
I use json_encode and json_decode.
Found it to be more reliable then serialize

Save to database
Code:
$string = json_encode($array);

json_encode wil return a string just like serialize does.
You can now save it to your DB. Don't forget to escape your string when saving it!

When retriving it from the database
Code:
$result = json_decode($db_result['your_json_string']);

This wil turn the json string into an object. To get the array do

Code:
$result = (array)json_decode($db_result['some_column']);

I don't know how you are returning your DB results, so this is just as an example.

Hope this helps you out!


Messages In This Thread
Saving an Array to Database - by El Forum - 10-05-2012, 10:48 PM
Saving an Array to Database - by El Forum - 10-05-2012, 10:55 PM
Saving an Array to Database - by El Forum - 10-05-2012, 11:11 PM
Saving an Array to Database - by El Forum - 10-05-2012, 11:51 PM
Saving an Array to Database - by El Forum - 10-06-2012, 12:29 AM
Saving an Array to Database - by El Forum - 10-06-2012, 12:46 AM
Saving an Array to Database - by El Forum - 10-06-2012, 01:16 AM
Saving an Array to Database - by El Forum - 10-06-2012, 02:44 AM
Saving an Array to Database - by El Forum - 10-06-2012, 10:57 AM
Saving an Array to Database - by El Forum - 10-06-2012, 11:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB