Cakephp - detect if unable to connect to database and recover gracefully
        Posted  
        
            by Phantz
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Phantz
        
        
        
        Published on 2010-03-25T05:43:24Z
        Indexed on 
            2010/03/25
            11:23 UTC
        
        
        Read the original article
        Hit count: 358
        
I have a few sites built with Cakephp. If any of these sites lose their connection to the database for whatever reason it does not handle it well. Basically it renders itself inside itself trying to display an error over and over until the browser crashes. The rendering itself inside itself is caused by the use of requestAction from elements.
What I want to know is how can I check if the database connection exists
I tried this in the app_controller before filter:
if(!ConnectionManager::getDataSource('default'))
 {
  die(); //this will be a message instead
 }
but it does not seem to work.
Thanks
© Stack Overflow or respective owner