if ($this->isSuccessful && $sql) {
$query =& new MySQLQuery($sql, $this->getDBConn()); // HAVE TO BUILD CUSTOMIZED QUERY HANDLING USING MySQLQuery OBJECT
ob_start();
$result = $query->getResult();
$error = ob_get_contents();
ob_end_clean();
$query = null;
if (mysql_error() || preg_match('/Fatal error/i', $error)) {
$this->isSuccessful = false;
$this->setErrorArray(array('action' => 'The query could not be performed: ' . nl2br(mysql_error())));
} else {
$_SESSION["${projectAcronym}_sql"] = $sql; // DON'T FORGET TO STORE THE SQL STATEMENT INTO A SESSION VARIABLE
if ($isAllowedSearchResultsReport && $searchResultsReportType && @sizeof($result) > 0)
$_SESSION["${projectAcronym}_search_results"] = serialize($result); // STORE SEARCH RESULTS IN SEPARATE SESSION TO USE TO GENERATE REPORT
}
}
This code works just fine except in one case: if the user enters information that chokes the MySQL query, producing a rather annoying Fatal Error:
{Quote]Fatal error: Got error 'repetition-operator operand invalid' from regexp using query:[/Quote]
This is due to the regexp portion of the query being malformed by user input. Instead of teaching every single client the right way of entering regular expression patterns in a query (RegExp 101!), I would like to offer up a friendlier way of dealing with this, which I thought would be to suppress the fatal error in this case and produce a friiendlier message and allow code execution to continue, basically the PHP equivalent of the Java try-catch:
try {
// DO STUFF THAT COULD BREAK
} catch (Exception e) {
// DO SOMETHING ELSE
}
What ideas might you have?
Thanx
Phil