Using Amazon Web Services With PHP And SOAP (part 2)
Add search features, shopping carts and wish lists to your AWS-backed online store.
| Rolling The Stones |
The first - and the simplest - type of search available in AWS is the keyword search, exposed via the KeywordSearchRequest() call. Here's a simple example of how it works:
// include class
// create a instance of the SOAP client object
$soapclient = new soapclient("http://soap.amazon.com/schemas2/AmazonWebServices.wsdl", true);
// set up an array containing input parameters to be
// passed to the remote procedure
$params = array(
'keyword' => 'rolling%20stones',
'page' => 1,
'mode' => 'books',
'tag' => 'melonfire-20',
'type' => 'lite',
'devtag' => 'YOUR-TOKEN-HERE'
// create a proxy so that WSDL methods can be accessed directly
$proxy = $soapclient->getProxy();
// invoke the method
$result = $proxy->KeywordSearchRequest($params);
// print the results
This is functionally similar to the scripts you've seen thus far; the primary difference lies in the call to a new function - KeywordSearchRequest() - and in the different arguments passed to it. The "keyword" argument passed to the function contains the words to be used as search keys in the specified Amazon catalog(s); note that this search term must be URL-encoded before being passed to the function.
Here's sample output from the script above:
''.preg_replace(array('/ /', '/ /'), array(' ', ' '), '
[TotalResults] => 163
[Details] => Array
 => Array
[Url] => http://www.amazon.com/exec/obidos/redirect?tag=melonfire-20%26creative=YOUR-TOKEN-HERE%26camp=2025%26link_code=sp1%26path=ASIN/1556523734
[Asin] => 1556523734
[ProductName] => Nankering With the Rolling Stones
[Catalog] => Book
[Authors] => Array
 => James Phelge
[ReleaseDate] => April, 2000
[Manufacturer] => A Cappella Books
[ImageUrlSmall] => http://images.amazon.com/images/P/1556523734.01.THUMBZZZ.jpg
[ImageUrlMedium] => http://images.amazon.com/images/P/1556523734.01.MZZZZZZZ.jpg
[ImageUrlLarge] => http://images.amazon.com/images/P/1556523734.01.LZZZZZZZ.jpg
[ListPrice] => $16.95
[OurPrice] => $11.87
[UsedPrice] => $10.95
... snip ...
Next, let's see how this can be integrated into the sample store I've been building.
How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.
Read more, or grab your copy now!