note 26880 added to language.oop.serialization

From: Date: Fri, 15 Nov 2002 16:10:55 +0000
Subject: note 26880 added to language.oop.serialization
Groups: php.notes 
Request: Send a blank email to php-notes+get-39546@lists.php.net to get a copy of this message
Serialization is very useful for the storing of objects in databases. The following example stores an obbect in a mySQL db: # Seperate Class. include 'thisObjectClass.php'; # Create instance of a class. $object = new thisObjectClass; # Create link to the database $link = mysql_connect('host', 'user', 'password'); mysql_select_db('dbname', $link); # Formulate query and submit. $sql_query = mysql_query("INSERT INTO objecttable(object) VALUES (serialize($object)") or print (mysql_error()); # Retrieve blob object. $sql_query = mysql_query("SELECT object FROM objecttable WHERE 1) or print (mysql_error()); $row = mysql_fetch_row($sql_query); # This should show string / text data. print $row[0]; # This should show 'object'. print unserialize($row[0])."<br>"; # Close db link. mysql_close($link); -- http://www.php.net/manual/en/language.oop.serialization.php http://master.php.net/manage/user-notes.php?action=edit+26880 http://master.php.net/manage/user-notes.php?action=delete+26880 http://master.php.net/manage/user-notes.php?action=reject+26880

« previous php.notes (#39546) next »