serialization - Why do you serialize an object for a database? -


i know serializing means not how apply it. when serialize object database. doesn't matter language here php.

<?php // $session_data contains multi-dimensional array session // information current user.  use serialize() store // in database @ end of request.  $conn = odbc_connect("webdb", "php", "chicken"); $stmt = odbc_prepare($conn,       "update sessions set data = ? id = ?"); $sqldata = array (serialize($session_data), $_server['php_auth_user']); if (!odbc_execute($stmt, $sqldata)) {     $stmt = odbc_prepare($conn,      "insert sessions (id, data) values(?, ?)");     if (!odbc_execute($stmt, $sqldata)) {         /* went wrong.. */     } } ?> 

why this? why wouldn't use regular query execute update or insert. read code comments i'm not grasping it.

edit: kind of information in session_data i'd need not have in regular column?

serialization typically used send objects between applications (machines, processes sometimes) through data stream, example - web service communication on http protocol, socket communication etc. in context of databases serialization needed when object, or part of can't stored in columns values of it's properties. such scenario can occur if forced store new data, can't update database's existing schema. perhaps use varchar column store more data in xml format, example. of course discouraged, when work legacy code there no other way.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -