JustinK101 Posted August 24, 2010 Share Posted August 24, 2010 What is the better way, in terms of best practice and also speed of storing PHP objects in a database? Is it: Serialize $SQL = "INSERT INTO my_table (my_object) VALUES ('" . seralize($php_object). "')"; OR JSON $SQL = "INSERT INTO my_table (my_object) VALUES ('" . json_encode($php_object). "')"; Any idea which is faster serialize() / unserialize() or json_ecode() / json_decode()? Quote Link to comment https://forums.phpfreaks.com/topic/211573-best-way-to-store-objects-in-a-database/ Share on other sites More sharing options...
trq Posted August 24, 2010 Share Posted August 24, 2010 You'd need to run your own benchmarks or Google it I would say. I doubt there would be much difference and I use serialization simply because php objects have nothing to do with javascript. Quote Link to comment https://forums.phpfreaks.com/topic/211573-best-way-to-store-objects-in-a-database/#findComment-1102978 Share on other sites More sharing options...
JustinK101 Posted August 24, 2010 Author Share Posted August 24, 2010 Just did a benchmark with 100,000 and 1,000,000, and serialize was 80% faster than json. Quote Link to comment https://forums.phpfreaks.com/topic/211573-best-way-to-store-objects-in-a-database/#findComment-1102993 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.