Hey, i’ve just made an iphone app and i’m getting the user to enter a search term. I’m then taking that search term and sending it up to a PHP page on my webhost, i’m then querying some RSS feeds and returning xml back down to the app. What i’m interesting in doing is logging the users search term into a DB and then returning the XML as normal. Whats obviously more important is that the user gets the xml rather than the term being logged. So what could i add to the below code to make sure the XML is safely returned regardless of whether the mysql fails?
Any ideas?
<?php
header("Content-type: text/xml");
//Gather data and prepare query
$thequery = urlencode($_GET['s']);
$yhost = 'http://boss.yahooapis.com';
$apikey = 'xxxxxxxxxxxxxxxxxxxxxxx';
$url = $yhost.'/ysearch/news/v1/'.$thequery.'?appid='.$apikey.'&format=xml';
//Get the results
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$results = new SimpleXmlElement($data, LIBXML_NOCDATA);
//echo the results
echo $results->asXML();
?>
You should be fine using standard DB syntax, eg:
What this will do is attempt to connect to your DB and run your insert (logging) query. Regardless of failure, the XML will then be output.