我有這樣的代碼的應用程序我的工作: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