Table of contents:
- What's new
- AMF Overview
- Installation
- Service Browser
- Installation
- Security
- Fundamentals
- Security
- Datatypes
- Class Mapping
- Sessions
- Creating Services
- Getting Started
- Debugging
- Tutorials
- AMFPHP Development
- Development Roadmap
- SVN Access
Storing a Blob
What is a blob? Blob is an acronym for binary large object. It is useful for storing an entire object in a database. It is supported in most, but not all databases. In postgresql a blob can be up to 1GB in size.
A full example of this will be coming soon.
Implementation
An example of a simple php service which takes an object from actionscript and sends it to postgresql for storage is the following:
/**
* @desc Takes in an object from flex for storage in db.
*
* @param object $order -- Entire order object.
* @return storage result. Returns ID for object if successful.
*/
public function storeOrder($order) {
$serObject = base64_encode(serialize($order));
return $this->orders->setOrderObject($serObject);
}
The store order method uses the following code to call a stored procedure which is used to store the object in postgresql:
/**
* @desc Used to store the order as a blob in postgresql.
* @return ID of the blob object in the database upon successful insertion.
* @throws PowersDataGatewayException if $spids argument is empty
* @throws DatabaseHelperException
*/
public function setOrderObject($order) {
$sp = $this->newStoredProcedure('sp_add_partial_order'); return $sp->call(array($order));
}
An example of a simple php service which retrieves an object from postgresql and forwards it on to actionscript is the following:
/**
* @desc Returns a blob object which contains an order.
*
* @param number objectID --ID of the object in the database.
* @return blob order object.
*/
public function getOrder($orderID) {
return unserialize(base64_decode($this->orders->getOrderObject($orderID)));
}
The example above uses the following code in order to get an object from postgresql:
/**
* @desc Used to retrieve the blob from postgresql.
* @return blob order object
* @throws DatabaseHelperException
*/
public function getOrderObject($orderID) {
$sp = $this->newStoredProcedure('SELECT * FROM sp_get_partial_order'); return $sp->call(array($orderID));
}
