phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Database: Storing Data Via Serialize and Unserialize

Tag: database, serialize   Category: PHP Database
post: 05 Feb 2008 read: 333


Serialize Database: This is also data storage alternative. You can use serialize() and and unserialize(), that convert a PHP variable into a storable (text) format and convert it back again. These functions are often used to store variables into databases, pass them between programs, or other such purposes. In this post, we use to create a file data storage.


<?php
$orig = array(
    array('name' => 'Apple', 'category' => 'Fruit'),
    array('name' => 'Grape', 'category' => 'Fruit'),
    array('name' => 'Elephant', 'category' => 'Animal'),
    array('name' => 'Dog', 'category' => 'Animal')
    );

file_put_contents('output.ize', serialize($orig), LOCK_EX);

$new = unserialize(file_get_contents('output.ize'));

echo "First Enter is: Name: {$new[0]['name']} Category: {$new[0]['category']}<br />";

echo '<pre>';
var_dump($new);
echo '</pre>';
?>



| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting