13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Solution Overview<br />

829<br />

Listing 33.7<br />

}<br />

return $ars;<br />

}<br />

Continued<br />

This function is designed to drive the process of getting data from Amazon. It can do<br />

this in two ways: either from the cache or live from Amazon. Because Amazon requires<br />

developers to cache downloaded data, the function first looks for data in the cache.We<br />

discuss the cache shortly.<br />

If you have not already performed this particular query, the data must be fetched live<br />

from Amazon.You do this by creating an instance of the AmazonResultSet class <strong>and</strong> calling<br />

the method on it that corresponds to the particular query you want to run.The type<br />

of query is determined by the $type parameter. In the category (or browse node) search<br />

example, you pass in browse as the value for this parameter (refer to Listing 33.6). If you<br />

want to perform a query about one particular book, you should pass in the value asin,<br />

<strong>and</strong> if you want to perform a keyword search, you should set the parameter to search.<br />

Each of these parameters invokes a different method on the AmazonResultSet class.<br />

The individual item search calls the ASINSearch() method.The category search calls the<br />

browseNodeSearch() method.The keyword search calls the keywordSearch() method.<br />

Let’s take a closer look at the AmazonResultSet class.The full code for this class is<br />

shown in Listing 33.8.<br />

Listing 33.8<br />

AmazonResultSet.php—A Class for H<strong>and</strong>ling Amazon Connections<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!