\n");
/**
* Error handler function
*
* This function will intercept PHP errors and print them
* in an XML-format. Otherwise MSXML will fail when atempting
* to parse the badly formatted errors and display nasty
* messages of lack of well-formedness.
*
* The function is made after an interface defined by PHP
*
* Based on function by Ola Grøstad
*/
function XMLErrorHandler($errno, $errstr, $errfile, $errline) {
global $mssqlerr; //Accessible by rest of script
/* Is this an MS SQL error? */
$ismssql = stristr( $errstr, 'mssql' );
$contextattr = $ismssql ? ' context="mssql"' : "";
$messageattr = $ismssql ? ' message="'. mssql_get_last_message() . '"' : "";
$errortype= "";
/* What kind of error is this */
switch ($errno){
case E_USER_ERROR:
echo "{$errstr}\n";
exit(1);
break;
case E_USER_WARNING: $errortype='error'; break;
case E_USER_NOTICE: $errortype='warning'; break;
default: $errortype='unknown'; break;
}
/* Store error in the global variable */
$mssqlerr .= " 0 ) { return false; }
return $session_id;
}
/**
* Logout and end a session in the database
* Args:
* $session_id - The id of the session to logout
* Returns:
* TRUE if the logout was sucessful, FALSE otherwise
*/
function logout( $session_id ) {
/* Call predefined stored procedure dbo.session_logout */
$query = << 0 begin
-- if @status = 0 commit transaction else rollback transaction
--end
select @status -- Get the error number
QUERY;
return getSingleValue($query);
/*
$res = mssql_query( $query );
$row = mssql_fetch_array( $res );
return $row[0];
*/
}
/**
* Retrieve a single value from an SQL result
*
* Retrieves a single, or the first value from
* an SQL result. Typically useful for retrieving
* a single XML result from an XQuery.
*
* Args:
* $query - SQl query to execute
* Returns:
* The first value from the first row of the SQL result.
*/
function getSingleValue( $query ) {
$results = mssql_query($query);
$row = mssql_fetch_array($results);
return $row[0];
}
/**
* Print XML data with a stylesheet reference
*
* Prints
*/
function printXMLData( $xml, $xslhref, $cache=true ) {
header('Content-type: text/xml; charset=UTF-8');
if ( ! $cache ) {
header("Cache-Control: must-revalidate, max-age=0");
}
echo XMLHEADER;
if ( $xslhref ) {
echo utf8_encode( '' . "\n" );
}
echo utf8_encode($xml);
}
?>