hsguy
asked on
PHP graceful exit -- Catching mysql error in an XML output
I'm trying to replace all the mysql_*() or die() constructs is a script and replace die with a more graceful -- and more useful exit upon an error.
Attached is my code using PHP 5 that does not do what I'd expect at all. The output contains an empty <message> tag.
Could someone point out what I'm doing wrong?
Thanks
Attached is my code using PHP 5 that does not do what I'd expect at all. The output contains an empty <message> tag.
Could someone point out what I'm doing wrong?
Thanks
<?php
function errorXML($error_message){
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<root>\n";
$xml_output .= "\t<error>\n";
$xml_output .= "\t\t<message>".$error_message."</message>\n";
$xml_output .= "\t</error>\n";
$xml_output .= "</root>";
outputXML($xml_output);
exit();
}
function outputXML($xml_output){
header("Content-type: text/xml");
echo ($xml_output);
}
$linkID = @mysql_connect("badhost", "baduser", "badpass") or errorXML(mysql_error());
@mysql_select_db("badsite", $linkID) or errorXML(mysql_error());
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
require_once('./../include
Which I deleted out of the code I posted--not event hinking that it could be the problem.
When I commented that line out, it worked as expected.
So the problem lies somewhere in that common.php
Thanks for the help!