Amazon SimpleDB Service (http://aws.amazon.com/simpledb)
2009.08.23
2006-2010 Ryan Parman, Foleeo, Inc., and contributors.
| Simplified BSD License | http://opensource.org/licenses/bsd-license.php |
| CloudFusion | http://getcloudfusion.com |
| Amazon SDB | http://aws.amazon.com/simpledb |
Specify the default queue URL.
Container for all Amazon SimpleDB-related methods. Inherits additional methods from CloudFusion.
CloudFusion
public function __construct( $key = null, $secret_key = null )
The constructor
public
| key | string (Optional) Your Amazon API Key. If blank, it will look for the AWS_KEY constant. |
| secret_key | string (Optional) Your Amazon API Secret Key. If blank, it will look for the AWS_SECRET_KEY constant. |
boolean false if no valid values are set, otherwise true.
public function create_domain( $domain_name, $returnCurlHandle = null )
Creates a new domain. The domain name must be unique among the domains associated with the Access Key ID provided in the request. The CreateDomain operation might take 10 or more seconds to complete.
public
| domain_name | string (Required) The domain name to use for storing data. |
| returnCurlHandle | boolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests. |
ResponseCore object
<?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->create_domain('warpshare-unit-test');
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?>| AWS Method | http://docs.amazonwebservices.com |
| Related | create_domain(), list_domains(), delete_domain(), domain_metadata() |
public function list_domains( $opt = null )
Lists all domains associated with the Access Key ID. It returns domain names up to the limit set by MaxNumberOfDomains. A NextToken is returned if there are more than MaxNumberOfDomains domains. Calling ListDomains successive times with the NextToken returns up to MaxNumberOfDomains more domain names each time.
public
| opt | array (Required) Associative array of parameters which can have the following keys: |
| MaxNumberOfDomains | integer (Optional) The maximum number of domain names you want returned. The range is 1 to 100. |
| NextToken | string (Optional) String that tells Amazon SimpleDB where to start the next list of domain names. |
| returnCurlHandle | boolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests. |
ResponseCore object
<?php // Dependencies require_once 'cloudfusion.class.php'; // Instantiate $sdb = new AmazonSDB(); $response = $sdb->list_domains(); // Success? var_dump($response->isOK()); /** [Expected output] bool(true) */ ?>
<?php // Dependencies require_once 'cloudfusion.class.php'; // Instantiate $sdb = new AmazonSDB(); $response = $sdb->list_domains(array( 'MaxNumberOfDomains' => 1 )); // Success? var_dump($response->isOK()); /** [Expected output] bool(true) */ ?>
<?php // Dependencies require_once 'cloudfusion.class.php'; // Instantiate $sdb = new AmazonSDB(); $response = $sdb->list_domains(array( 'NextToken' => 't' )); // Success? var_dump($response->isOK()); /** [Expected output] bool(true) */ ?>
<?php // Dependencies require_once 'cloudfusion.class.php'; // Instantiate $sdb = new AmazonSDB(); $response = $sdb->list_domains(array( 'MaxNumberOfDomains' => 1, 'NextToken' => 't' )); // Success? var_dump($response->isOK()); /** [Expected output] bool(true) */ ?>
| AWS Method | http://docs.amazonwebservices.com |
| Related | create_domain(), list_domains(), delete_domain(), domain_metadata() |
public function delete_domain( $domain_name, $returnCurlHandle = null )
Deletes a domain. Any items (and their attributes) in the domain are deleted as well. The DeleteDomain operation might take 10 or more seconds to complete. Running DeleteDomain on a domain that does not exist or running the function multiple times using the same domain name will not result in an error response.
public
| domain_name | string (Required) The domain name to delete. |
| returnCurlHandle | boolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests. |
ResponseCore object
<?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->delete_attributes('warpshare-unit-test', 'unit-test');
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?> <?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->delete_attributes('warpshare-unit-test', 'unit-test', 'key1');
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?> <?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->delete_attributes('warpshare-unit-test', 'unit-test', array(
'key2' => 'value1'
));
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?> <?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->delete_attributes('warpshare-unit-test', 'unit-test', array(
'key2',
'key3'
));
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?>| AWS Method | http://docs.amazonwebservices.com |
| Related | create_domain(), list_domains(), delete_domain(), domain_metadata() |
public function domain_metadata( $domain_name, $returnCurlHandle = null )
Returns information about the domain, including when the domain was created, the number of items and attributes, and the size of attribute names and values.
public
| domain_name | string (Required) The domain name to use for retrieving metadata. |
| returnCurlHandle | boolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests. |
ResponseCore object
<?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->domain_metadata('warpshare-unit-test');
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?>| AWS Method | http://docs.amazonwebservices.com |
| Related | create_domain(), list_domains(), delete_domain(), domain_metadata() |
public function put_attributes( $domain_name, $item_name, $keypairs, $replace = null, $returnCurlHandle = null )
Creates or replaces attributes in an item. You specify new attributes using a combination of the Attribute.X.Name and Attribute.X.Value parameters.
public
| domain_name | string (Required) The domain name to use for storing data. |
| item_name | string (Required) The name of the base item which will contain the series of keypairs. |
| keypairs | array (Required) Associative array of parameters which are treated as key-value and key-multivalue pairs (i.e. a key can have one or more values; think tags). |
| replace | boolean|array (Optional) Whether to replace a key-value pair if a matching key already exists. Supports either a boolean (which affects ALL key-value pairs) or an indexed array of key names (which affects only the keys specified). Defaults to boolean false. |
| returnCurlHandle | boolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests. |
ResponseCore object
<?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->put_attributes('warpshare-unit-test', 'unit-test', array(
'key1' => 'value1',
'key2' => array(
'value1',
'value2',
'value3'
)
));
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?> <?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->put_attributes('warpshare-unit-test', 'unit-test', array(
'key1' => 'value1',
'key2' => array(
'value1',
'value2',
'value3'
)
), true);
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?> <?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->put_attributes('warpshare-unit-test', 'unit-test', array(
'key1' => 'value1',
'key2' => array(
'value1',
'value2',
'value3'
)
), array('key1'));
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?>| AWS Method | http://docs.amazonwebservices.com |
| Related | get_attributes(), delete_attributes() |
public function batch_put_attributes( $domain_name, $item_keypairs, $replace = null, $returnCurlHandle = null )
Creates or replaces attributes in an item. You specify new attributes using a combination of the Attribute.X.Name and Attribute.X.Value parameters.
public
| domain_name | string (Required) The domain name to use for storing data. |
| item_keypairs | array (Required) Associative array of parameters which are treated as item-key-value and item-key-multivalue pairs (i.e. a key can have one or more values; think tags). |
| replace | boolean|array (Optional) Whether to replace a key-value pair if a matching key already exists. Supports either a boolean (which affects ALL key-value pairs) or an indexed array of key names (which affects only the keys specified). Defaults to boolean false. |
| returnCurlHandle | boolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests. |
ResponseCore object
<?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
// Test data
$response = $sdb->batch_put_attributes('warpshare-unit-test', array(
'item1' => array(
'key1' => 'value1',
'key2' => array(
'value1',
'value2',
'value3',
),
'key3' => array('value1'),
),
'item2' => array(
'key1' => 'value1',
'key2' => array(
'value1',
'value2',
'value3',
),
'key3' => array('value1'),
),
'item3' => array(
'key1' => 'value1',
'key2' => array(
'value1',
'value2',
'value3',
),
'key3' => array('value1'),
),
));
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?> <?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
// Test data
$response = $sdb->batch_put_attributes('warpshare-unit-test', array(
'item1' => array(
'key1' => 'value1',
'key2' => array(
'value1',
'value2',
'value3',
),
'key3' => array('value1'),
),
'item2' => array(
'key1' => 'value1',
'key2' => array(
'value1',
'value2',
'value3',
),
'key3' => array('value1'),
),
'item3' => array(
'key1' => 'value1',
'key2' => array(
'value1',
'value2',
'value3',
),
'key3' => array('value1'),
),
), true);
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?> <?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
// Test data
$response = $sdb->batch_put_attributes('warpshare-unit-test', array(
'item1' => array(
'key1' => 'value1',
'key2' => array(
'value1',
'value2',
'value3',
),
'key3' => array('value1'),
),
'item2' => array(
'key1' => 'value1',
'key2' => array(
'value1',
'value2',
'value3',
),
'key3' => array('value1'),
),
'item3' => array(
'key1' => 'value1',
'key2' => array(
'value1',
'value2',
'value3',
),
'key3' => array('value1'),
),
), array(
'item1' => array(
'key2'
),
'item3' => array(
'key3'
),
));
$url = $response->header['_info']['url'];
// Are these stored in the URL properly?
var_dump((stristr($url, 'Item.0.Attribute.0.Replace') !== false) ? true : false);
var_dump((stristr($url, 'Item.0.Attribute.1.Replace') !== false) ? true : false);
var_dump((stristr($url, 'Item.0.Attribute.2.Replace') !== false) ? true : false);
var_dump((stristr($url, 'Item.0.Attribute.3.Replace') !== false) ? true : false);
var_dump((stristr($url, 'Item.2.Attribute.5.Replace') !== false) ? true : false);
/** [Expected output]
bool(false)
bool(true)
bool(true)
bool(true)
bool(true)
*/
?>| AWS Method | http://docs.amazonwebservices.com |
| Related | get_attributes(), delete_attributes() |
public function get_attributes( $domain_name, $item_name, $keys = null, $returnCurlHandle = null )
Returns all of the attributes associated with the item. Optionally, the attributes returned can be limited to one or more specified attribute name parameters. If the item does not exist on the replica that was accessed for this operation, an empty set is returned. The system does not return an error as it cannot guarantee the item does not exist on other replicas.
public
| domain_name | string (Required) The domain name to use for storing data. |
| item_name | string (Required) The name of the base item which will contain the series of keypairs. |
| keys | string|array (Optional) The name of the key (attribute) in the key-value pair that you want to return. Supports a string value (for single keys) or an indexed array (for multiple keys). |
| returnCurlHandle | boolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests. |
ResponseCore object
<?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->get_attributes('warpshare-unit-test', 'unit-test');
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?> <?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->get_attributes('warpshare-unit-test', 'unit-test', array(
'key1'
));
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?> <?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->get_attributes('warpshare-unit-test', 'unit-test', 'key1');
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?>| AWS Method | http://docs.amazonwebservices.com |
| Related | put_attributes(), delete_attributes() |
public function delete_attributes( $domain_name, $item_name, $keys = null, $returnCurlHandle = null )
Deletes one or more attributes associated with the item. If all attributes of an item are deleted, the item is deleted. If you specify DeleteAttributes without attributes or values, all the attributes for the item are deleted. DeleteAttributes is an idempotent operation; running it multiple times on the same item or attribute does not result in an error response.
public
| domain_name | string (Required) The domain name to use for storing data. |
| item_name | string (Required) The name of the base item which will contain the series of keypairs. |
| keys | string|array (Optional) The name of the key (attribute) in the key-value pair that you want to delete. Supports a string value (for single keys), an indexed array (for multiple keys), or an associative array containing one or more key-value pairs (for deleting specific values). |
| returnCurlHandle | boolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests. |
ResponseCore object
<?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->delete_attributes('warpshare-unit-test', 'unit-test');
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?> <?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->delete_attributes('warpshare-unit-test', 'unit-test', 'key1');
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?> <?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->delete_attributes('warpshare-unit-test', 'unit-test', array(
'key2' => 'value1'
));
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?> <?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->delete_attributes('warpshare-unit-test', 'unit-test', array(
'key2',
'key3'
));
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?>| AWS Method | http://docs.amazonwebservices.com |
| Related | put_attributes(), get_attributes() |
public function select( $expression, $opt = null )
The Select operation returns a set of Attributes for ItemNames that match the query expression. Select is similar to the standard SQL SELECT statement.
The total size of the response cannot exceed 1 MB in total size. Amazon SimpleDB automatically adjusts the number of items returned per page to enforce this limit. For example, even if you ask to retrieve 250 items, but each individual item is 100 kB in size, the system returns 10 items and an appropriate next token so you can get the next page of results.
public
| expression | string (Optional) The SimpleDB select expression to use. |
| opt | array (Optional) Associative array of parameters which can have the following keys: |
| NextToken | string (Optional) String that tells Amazon SimpleDB where to start the next list of domain names. |
| returnCurlHandle | boolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request. This is useful for MultiCURL requests. |
ResponseCore object
<?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->select('SELECT * FROM `warpshare-unit-test`');
// Success?
var_dump($response->isOK());
/** [Expected output]
bool(true)
*/
?> <?php
// Dependencies
require_once 'cloudfusion.class.php';
// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->select('SELECT * FROM `warpshare-unit-test`', array(
'NextToken' => 't'
));
// Success?
var_dump($response->body->Errors->Error->Code);
/** [Expected output]
object(SimpleXMLElement)#6 (1) {
[0]=>
string(16) "InvalidNextToken"
}*/
?>| AWS Method | http://docs.amazonwebservices.com |
| Related | select() |