Exemplo n.º 1
0
 *
 * or in the "license.txt" file accompanying this file. This file is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the
 * License.
 *
 * Modified by Jeffrey S. Haemer <*****@*****.**>
 */
error_reporting(E_ALL);
require_once 'AWSSDKforPHP/sdk.class.php';
require_once 'include/book.inc.php';
// Create the SimpleDB access object
$sdb = new AmazonSDB();
// Query for each file
$res1 = $sdb->select("select * from " . BOOK_FILE_DOMAIN);
if ($res1->isOK()) {
    foreach ($res1->body->SelectResult->Item as $item) {
        $itemName = (string) $item->Name;
        // Delete the attributes
        $res2 = $sdb->delete_attributes(BOOK_FILE_DOMAIN, $itemName);
        if ($res2->isOK()) {
            print "Deleted item {$itemName}\n";
        } else {
            $error = $res2->body->Errors->Error->Message;
            print "Could not delete item: {$error}\n";
        }
    }
} else {
    $error = $res1->body->Errors->Error->Message;
    exit("Could not run query: {$error}\n");
Exemplo n.º 2
0
<?php

require_once './sdk.class.php';
error_reporting(-1);
ini_set('display_errors', true);
header("Content-type: text/html; charset=utf-8");
$sdb = new AmazonSDB();
$domain = 'authors';
//$authors_domain = $sdb->create_domain($domain);
/*$add_authors = $sdb->batch_put_attributes($domain, array(
		'*****@*****.**' => array(
				'name' => 'Behrouz A Forouzan',
				'password' => '1a1dc91c907325c69271ddf0c944bc72', //MD5 of 'pass'
				'type' => '1',
			),
		'*****@*****.**' => array(
				'name' => 'Dennis M. Ritchie',
				'password' => '1a1dc91c907325c69271ddf0c944bc72', //MD5 of 'pass'
				'type' => '1',
		),
		));*/
$sdb->delete_attributes($domain, "author_2", array(array('Name' => 'name'), array('Name' => 'password')));
$query = "SELECT name,password FROM `{$domain}`";
$results = $sdb->select($query);
$authors = $results->body->Item();
foreach ($authors as $author) {
    echo $author->Attribute[0]->Value;
    echo "</br>";
}
<?php

// Set the response class on a new AmazonSDB object
$sdb = new \AmazonSDB();
$sdb->set_response_class('\\ORM\\SDB\\SDBResponse');
// ---------------------
// Using get_attributes() (retrieves one item's attributes)
$attributes = $sdb->get_attributes('myDomain', 'item1');
// You can still use CFResponse features
if (!$attributes->isOK()) {
    die("Oh no! There's a problem");
}
// $attributes is now accessible as an array of key->value pairs associated with item1
echo "My item {$attributes['id']} has the name {$attributes['name']}";
// -------------
// Using select() (retrieves any number of items)
$items = $sdb->select('SELECT * FROM myDomain');
// Count will work
echo "Returned ", count($items), " items.";
foreach ($items as $itemName => $itemAttributes) {
    echo "Item: {$itemName}\n";
    // Print out all the attributes of this item
    print_r($itemAttributes);
}
Exemplo n.º 4
0
if ($argc > 1) {
    $query .= " where ";
    for ($i = 1; $i < $argc; $i++) {
        $query .= ' ' . $argv[$i] . ' ';
    }
}
print "Final query: {$query}\n";
// Create the SimpleDB access object
$sdb = new AmazonSDB();
$recordCount = 0;
$totalUsage = 0;
// Query the SimpleDB domain
$next = null;
do {
    $attrs = $next == null ? null : array('NextToken' => $next);
    $res = $sdb->select($query, $attrs);
    $next = (string) $res->body->SelectResult->NextToken;
    // Check result
    if (!$res->isOK()) {
        exit("Select operation failed\n");
    }
    // Display results
    foreach ($res->body->SelectResult->Item as $item) {
        $recordCount++;
        foreach ($item->Attribute as $attribute) {
            print $attribute->Name . ": " . $attribute->Value . ", ";
            if ($attribute->Name == 'UsageValue') {
                $totalUsage += (int) $attribute->Value;
            }
        }
        print "\n";
Exemplo n.º 5
0
 *
 *       http://aws.amazon.com/apache2.0/
 *
 * or in the "license.txt" file accompanying this file. This file is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the
 * License.
 */
error_reporting(E_ALL);
require_once 'tarzan.class.php';
require_once 'book.php';
// Create the SimpleDB access object
$sdb = new AmazonSDB();
// Query for each file
$res1 = $sdb->select("select * from " . CL_ITEM_DOMAIN);
if ($res1->isOK()) {
    foreach ($res1->body->SelectResult->Item as $item) {
        $itemName = $item->Name;
        // Get list of attributes
        $attrs = array_keys(getItemAttributes($item));
        // Delete the attributes
        $res2 = $sdb->delete_attributes(CL_ITEM_DOMAIN, $itemName, $attrs);
        if ($res2->isOK()) {
            print "Deleted item {$itemName}\n";
        } else {
            $error = $res2->body->Errors->Error->Message;
            print "Could not delete item: {$error}\n";
        }
    }
} else {
Exemplo n.º 6
0
 *
 * Modified by Jeffrey S. Haemer <*****@*****.**>
 */
error_reporting(E_ALL);
require_once 'AWSSDKforPHP/sdk.class.php';
require_once 'include/book.inc.php';
// Set the query
$query = "select * from " . BOOK_FILE_DOMAIN;
if ($argc > 1) {
    $query .= " where ";
    for ($i = 1; $i < $argc; $i++) {
        $query .= ' ' . $argv[$i] . ' ';
    }
}
print "Final query: {$query}\n";
// Create the SimpleDB access object
$sdb = new AmazonSDB();
// Query the SimpleDB domain
$res = $sdb->select($query);
// Check result
if (!$res->isOK()) {
    exit("Select operation failed\n");
}
// Display results
foreach ($res->body->SelectResult->Item as $item) {
    foreach ($item->Attribute as $attribute) {
        print $attribute->Name . ": " . $attribute->Value . ", ";
    }
    print "\n";
}
exit(0);
Exemplo n.º 7
0
require_once('AWSSDKforPHP/sdk.class.php');
require_once('include/book.inc.php');

// Create the SimpleDB access object
$sdb = new AmazonSDB();

// Set list of attributes to delete
$attrs = array('ModTime', 'Flavor');

// Query for each item
$next = null;
do
{
  $attrs = ($next == null) ? null : array('NextToken' => $next);
  $res1 = $sdb->select("select * from " . BOOK_AWS_USAGE_DOMAIN, $attrs);
  $next  = (string) $res1->body->SelectResult->NextToken;

  if ($res1->isOK())
  {
    foreach ($res1->body->SelectResult->Item as $item)
    {
      $itemName = $item->Name;

      // Delete the attributes
      $res2 = $sdb->delete_attributes(BOOK_AWS_USAGE_DOMAIN, $itemName);

      if ($res2->isOK())
      {
	print("Deleted item $itemName\n");
      }
$domain = 'php-sdk-getting-started';
// Create the domain
$new_domain = $sdb->create_domain($domain);
// Was the domain created successfully?
if ($new_domain->isOK()) {
    // Add a batch of item-key-values to your domain
    $add_attributes = $sdb->batch_put_attributes($domain, array('Item_01' => array('Category' => 'Clothes', 'Subcategory' => 'Sweater', 'Name' => 'Cathair Sweater', 'Color' => 'Siamese', 'Size' => array('Small', 'Medium', 'Large')), 'Item_02' => array('Category' => 'Clothes', 'Subcategory' => 'Pants', 'Name' => 'Designer Jeans', 'Color' => 'Paisley Acid Wash', 'Size' => array('30x32', '32x32', '32x34')), 'Item_03' => array('Category' => 'Clothes', 'Subcategory' => 'Pants', 'Name' => 'Sweatpants', 'Color' => array('Blue', 'Yellow', 'Pink'), 'Size' => 'Large', 'Year' => array('2006', '2007')), 'Item_04' => array('Category' => 'Car Parts', 'Subcategory' => 'Engine', 'Name' => 'Turbos', 'Make' => 'Audi', 'Model' => 'S4', 'Year' => array('2000', '2001', '2002')), 'Item_05' => array('Category' => 'Car Parts', 'Subcategory' => 'Emissions', 'Name' => 'O2 Sensor', 'Make' => 'Audi', 'Model' => 'S4', 'Year' => array('2000', '2001', '2002'))));
    // Were the attributes added successfully?
    if ($add_attributes->isOK()) {
        // Add an additional size to Item_01
        $append_attributes = $sdb->put_attributes($domain, 'Item_01', array('Size' => 'Extra Large'));
        // Were the new attributes appended successfully?
        if ($append_attributes->isOK()) {
            // Use a SELECT expression to query the data.
            // Notice the use of backticks around the domain name.
            $results = $sdb->select("SELECT * FROM `{$domain}` WHERE Category = 'Clothes'");
            // Get all of the <Item> nodes in the response
            $items = $results->body->Item();
            // Re-structure the data so access is easier (see helper function below)
            $data = reorganize_data($items);
            // Generate <table> HTML from the data (see helper function below)
            $html = generate_html_table($data);
        }
    }
}
/*%******************************************************************************************%*/
// HELPER FUNCTIONS
function reorganize_data($items)
{
    // Collect rows and columns
    $rows = array();
Exemplo n.º 9
0
 public function testErrorMessage()
 {
     $results = $this->object->select('SELECT * FROM nonexistant');
     $this->assertFalse($results->isOK(), "Response was OK, when it shouldn't be!");
     $this->assertEquals($results->errorMessage(), "The specified domain does not exist.");
 }