PHP Classes

Object Manager: Store and retrieve objects in MySQL table records

Recommend this page to a friend!
  Info   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 387 All time: 6,672 This week: 206Up
Version License PHP version Categories
objectmanager 1.1GNU General Publi...5.0PHP 5, Databases
Description 

Author

This class can be used to store and retrieve objects in MySQL table records.

It serializes and unserializes objects to store and retrieve it in a given table. It can also query, update and delete an object given the identifier used to store it in the MySQL table.

The class can also create the necessary tables to store objects of different classes.

Picture of David Johns
Name: David Johns <contact>
Classes: 2 packages by
Country: United Kingdom
Age: 60
All time rank: 215899 in United Kingdom
Week rank: 321 Up14 in United Kingdom Up

Details

objectManager.class v2.2 Not only does this class allow an object of another class, be stored it also allows updating, deleting and querying using SQL like syntax. The whole process has been simplified and streamlined since version 1. Each class that requires persistence, must have a class variable $oid. This is a unique identifier for each object of that class. In order to query the object, class variables must be defined. Private and protected variables cannot be queried. Each class is stored in its own file. The path to the directory where the file is stored must be set, and that directory must be made writable. Improvements since version 1. 1) Does not use a database. 2) Simplified syntax 3) Full querying 4) Results ordering 5) Persistent classes are full portable Read me. Suggested location for your classes and objectManager.class is /classes. Suggested location for the storage files for your classes is /classes/data. This file must have its permission set to allow reading & writing to file. The following examples use an item class. For exampe $obMan= new objectManager("item","../classes/data/"); To save (insert) an object. $item=$obMan->insert($item); To retrieve an object, where the id of the object is know $id is the unique identifier for that class and must be an Integer. $item=$obMan->loadByID($id); To update that object $item->setName(‘edit this’); $obMan->update($item); To delete an object. Either: $obMan->deleteByID($id); Or $obMan->delete($item); Queries Order by surname Ascending $obMan->setOrder("surname",true); Order by surname Descending $obMan->setOrder("surname",false); Select all * $obMan->ORQuery("oid > 0"); Queries are split into AND or OR queries. Though it is hoped to improve the syntax in the future. Each element of the query must be separated by a space. For instance. $obMan->ANDQuery("oid > 100 firstname LIKE david "); SQL like keywords = (equality) > (Greater) < (less) <= (Less than equals) x <= y >=(Greater than equals) y >= x NOT= (not equality) LIKE (similar to SQL LIKE but cannot use wildcard) BEGIN (Word begins with character) $name BEGIN d //returns all the names that begin with d. Please note that all statements are case sensitive. And that strings unlike SQL do not use ‘ string‘ to identify them. Obtain results set. $itemList=$obMan->getResults(); //always returns an array of ids. foreach($itemList as $list){ $itemt = new item(); $item=$obMan->loadByID($listl); } To get ordered results, the correct order must be followed Set order Query Get results Please see http://www.phpobject.org/ for updates and further examples. To report bugs please use bugs@phpobject.org To contact me (David Johns) or become part of this project please use david@phpobject.org

  Files folder image Files  
File Role Description
Plain text file objectManager.class.php Class main class
Accessible without login Plain text file readme.txt Doc. Basic examples and implementation for Version 2

 Version Control Unique User Downloads Download Rankings  
 0%
Total:387
This week:0
All time:6,672
This week:206Up