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()? 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. 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. 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
Archived
This topic is now archived and is closed to further replies.