PHP Classes
elePHPant
Icontem

Kitchen Sink: Save and load any type of value in a SQL database

Recommend this page to a friend!
  Info   View files Documentation   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-06-16 (13 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
kitchen-sink 1.0Custom (specified...5PHP 5, Databases, Cache
Description Author

This package can Save and load any type of value in a SQL database.

It can store a value of arbitrary type associated with a given key name.

The values are stored in a SQL database table using the serialized value to store in the table.

The package also retrieve or remove an entry by key name.

  Performance   Level  
Name: Jon Lennryd <contact>
Classes: 1 package by
Country: Sweden Sweden

Details

kitchen_sink

Allow you to quickly save and retrieve any type of value in a kitchen_sink mysql table.

The KitchenSink.php is adapted for Cake PHP 2, while the KitchenSinkTable.php is adapted for Cake 3.

This is a 'everything and the kitchen sink' table, where you can store any type of value through Store(). You give your data a key, a unique name, to identify it.

It uses php's serialize() to convert any (well, I guess most) type of php data type and arrays into a serialized string.

Get your data back with a call to Retrieve().

Delete your data with Forget().

You can find a real usage example in this project: https://github.com/Snorvarg/simplicity

Examples for Cake 2: (Also found in source file)

// Store an array of data about flowers.
$this->loadModel('KitchenSink');
$this->KitchenSink->Store("flowers",array('flowers' => 'sweet', 'numbers_in_a_set' => 12));

// Refetch the data from database. 
$val = $this->KitchenSink->Retrieve("flowers");
debug($val); // The array of valuable flowers-data.

// Remove from database.
$this->KitchenSink->Forget("flowers");

// Now this will give null.
$val = $this->KitchenSink->Retrieve("flowers");
debug($val); // null, does no longer exist

// Several calls to Store() with same key will overwrite old value.
$this->KitchenSink->Store("Monkeys", array("Messy things in trees."));
$this->KitchenSink->Store("Monkeys", array("Monkeys in the djungle."));

Examples for Cake 3:

$kitchenSink = TableRegistry::get('KitchenSink');

$kitchenSink->Store('apples', array('green', 'red' => 12, 'blue' => array('no!!'), 'yellow' => 2));
$appleInfo = $kitchenSink->Retrieve('apples');

$kitchenSink->Forget('apples');
$whatApples = $kitchenSink->Retrieve('apples'); // Returns null.

$nullIfNotThere = $kitchenSink->Retrieve('FancyKey');

// This is a nice shortcut to give a default value if there is none in database.
$alwaysDefined = $kitchenSink->Retrieve('ScreaminglyFancyKey', 'a default value here');
  Files folder image Files  
File Role Description
Plain text file KitchenSink.php Class Class source
Plain text file KitchenSinkTable.php Class Class source
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads  
 100%
Total:0
This week:0