Ah, that’s because the DBAPI appears to automatically force the display of that error by calling a function called messageQuit():
if (!$this->conn = ($persist ? mysql_pconnect($host, $uid, $pwd) : mysql_connect($host, $uid, $pwd, true))) {
$modx->messageQuit("Failed to create the database connection!");
exit;
} else {
$dbase = str_replace('`', '', $dbase); // remove the `` chars
if (!@ mysql_select_db($dbase, $this->conn)) {
$modx->messageQuit("Failed to select the database '" . $dbase . "'!");
exit;
}
You will need to modify that to return false so you can detect if the connection was not successful without getting that error display.
I use PDO (and xPDO) for connecting to external databases personally (and in the upcoming Revolution release), but it might be good to record this as a bug in Jira for the 0.9.6.x versions so it gets addressed.