Hi all
To make clear to users which corpora are currently available and which
aren't, I'm checking to see if a BaseX server instance exists and then check
if a specific database exists. Testing for the database is done with
db:query (as I learned through this mailinglist), but I'm not sure how I can
silently test for the server in PHP.
All BaseX examples use try-catch blocks, which makes sense to catch errors
that go wrong, and do something with them. If I'm not mistaken these errors
are automatically logged by Apache (maybe also by other webservices). This
means that if I'm only checking the existence of a server with the code
below (variables left out), I will always write an error to a log file.
Obviously, that is not what I want because I know that the error 'Cannot
communicate with server' is to be expected when the server does not exist!
try {
$session = new Session($dbhost, $dbport, $dbuser, $dbpwd);
// db:exists returns a string 'false', still need to convert to
bool
$corpusExists =
toBoolean($session->query("db:exists('$databaseName')")->execute());
$session->close();
if ($corpusExists) {
$availabilityArray[] = $databaseName;
}
} catch (Exception $e) {
//
}
This script works perfectly fine, but I do not want the errors to be logged
(for this case) to prevent my error log to be full of the same error. Is
there another way to test for a BaseX instance only? For instance, a way to
return false when the server does not exist, I could do something like:
$session = new Session($dbhost, $dbport, $dbuser, $dbpwd);
If ($session) {
// db:exists returns a string 'false', still need to convert to
bool
$corpusExists =
toBoolean($session->query("db:exists('$databaseName')")->execute());
$session->close();
if ($corpusExists) {
$availabilityArray[] = $databaseName;
}
}
Thank you in advance
Bram Vanroy