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.

834 Chapter 33 Connecting to <strong>Web</strong> Services with XML <strong>and</strong> SOAP<br />

Listing 33.8<br />

Continued<br />

'SearchIndex' => $this->SearchIndex, 'Keywords' => $this->Keywords);<br />

$parameters = array('AWSAccessKeyId' => DEVTAG,<br />

'AssociateTag' => ASSOCIATEID, 'Request'=>array($request));<br />

// perform actual soap query<br />

$result = $soap_proxy->ItemSearch($parameters);<br />

if(isSOAPError($result)) {<br />

return false;<br />

}<br />

$this->totalResults = $result['TotalResults'];<br />

foreach($result['Items']['Item'] as $product) {<br />

$this->products[] = new Product($product);<br />

}<br />

unset($soapclient);<br />

unset($soap_proxy);<br />

} else {<br />

$this->url = "http://ecs.amazonaws.com/onca/xml?".<br />

"Service=".$this->Service.<br />

"&Operation=".$this->Operation.<br />

"&AssociateTag=".$this->AssociateTag.<br />

"&AWSAccessKeyId=".$this->AWSAccessKeyId.<br />

"&ResponseGroup=".$this->ResponseGroup.<br />

"&SearchIndex=".$this->SearchIndex.<br />

"&Keywords=".$this->Keywords;<br />

$this->parseXML();<br />

}<br />

return $this->products;<br />

}<br />

// Parse the XML into Product object(s)<br />

function parseXML() {<br />

// suppress errors because this will fail sometimes<br />

$xml = @simplexml_load_file($this->url);<br />

if(!$xml) {<br />

//try a second time in case just server busy<br />

$xml = @simplexml_load_file($this->url);<br />

if(!$xml) {

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

Saved successfully!

Ooh no, something went wrong!