我有这样的代码的应用程序我的工作:PHP脚本继续如果MySQL失败
<?php
header("Content-type: text/xml");
//Gather data and prepare query
$thequery = urlencode($_GET['s']);
$yhost = 'http://boss.yahooapis.com';
$apikey = 'xxxxxxxxxxxxxxxxxxxxxxxx';
$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);
$data = str_replace(array('<abstract>', '</abstract>'), array('<description>', '</description>'), $data);
$results = new SimpleXmlElement($data, LIBXML_NOCDATA);
//echo the results
echo $results->asXML();
?>
在那里我有这样一行:$thequery = urlencode($_GET['s']);
我想这个记录到数据库,但其明显非常重要的是XML被输出,所以我怎样才能确定,如果MySQL位因任何原因失败,XML仍然会输出?还是我过分复杂呢?
感谢这个...这个虽然,MySQL的错误要予以处理,其更重要的是,XML被输出,而不是MySQL错误得到解决...... – benhowdle89 2010-11-22 11:17:17
哪来的问题?只要执行if($ ret!= false){输出你的mysql的东西}',if子句将不会被执行,如果有Mysql错误的话。 – joni 2010-11-22 11:20:48