Edit your webroot/index.php file and look for the following lines:
$Dispatcher=new Dispatcher();
$Dispatcher->dispatch($url);
Just before these two lines try adding the following code:
$ConnectionManager =& ConnectionManager::getInstance();
$DataSource = @$ConnectionManager->getDataSource('default');
$connected = @$DataSource->connect();
if (!$connected)
{
echo '<strong>COULD NOT CONNECT to database.</strong><br /><br />';
echo 'Current Settings:';
echo '<ul>';
echo '<li>HOST: ' . $DataSource->config['host'] . '</li>';
echo '<li>USER: ' . $DataSource->config['login'] . '</li>';
echo '<li>DATABASE: ' . $DataSource->config['database'] . '</li>';
echo '</ul>';
exit;
}
else
{
$DataSource->disconnect();
}
Note that the @ at these two lines:
$DataSource = @$ ConnectionManager->getDataSource('default');
$connected= @$ DataSource->connect();
are needed because otherwise you would get warning messages coming from your
connection. So with the @ at the beginning we avoid these functions
outputting any disturbing message and instead use the returning boolean
value from connect() to check the connection.
-MI
---------------------------------------------------------------------------
Remember, smart coders answer ten questions for every question they ask.
So be smart, be cool, and share your knowledge.
BAKE ON!
-----Mensaje original-----
De: [email protected] [mailto:[EMAIL PROTECTED] En nombre
de Brad Daily
Enviado el: Jueves, 30 de Noviembre de 2006 12:09 a.m.
Para: Cake PHP
Asunto: Catching DB connection failure
We are using Cake in a project that will eventually be distributed to
be installed on a user's server. One thing I am struggling with is how
to catch when they have entered the wrong connection details for their
particular database server in the configuration file. Is there an easy
way to catch when the database connection has failed?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---