This is how Cake does it in the scaffold home page:

<?php
if (isset($filePresent)):
        uses('model' . DS . 'connection_manager');
        $db = ConnectionManager::getInstance();
        $connected = $db->getDataSource('default');
?>
<p>
        <?php
                if ($connected->isConnected()):
                        echo '<span class="notice success">';
                                __('Cake is able to connect to the database.');
                        echo '</span>';
                else:
                        echo '<span class="notice">';
                                __('Cake is NOT able to connect to the 
database.');
                        echo '</span>';
                endif;
        ?>
</p>
<?php endif;?>


On Aug 26, 8:33 pm, aranworld <[EMAIL PROTECTED]> wrote:
> I wonder if we have the same web host ... Hostway perhaps?
>
> I am just in the middle of figuring this out as well and I came across
> the following code that I believe still works, however, I must warn
> you that I have not tested this out fully, but maybe this will at
> least put you in the right direction?
>
> $db =& ConnectionManager::getDataSource('default');
> if(empty($db->connection)){
>     // you don't have a connection
>
> }
>
> On Aug 26, 10:55 am, "Samuel DeVore" <[EMAIL PROTECTED]> wrote:
>
> > I use the php functions for connecting to the database and then
> > redirect if it fails to a static page, usually from bootstrap.php if I
> > find that it becomes a problem on a host.
>
> > Sam D
> > --
> > (the old fart) the advice is free, the lack of crankiness will cost you
>
> > - its a fine line between a real question and an idiot
>
> >http://blog.samdevore.com/archives/2007/03/05/when-open-source-bugs-m...
>
> > On Tue, Aug 26, 2008 at 10:51 AM, bbf <[EMAIL PROTECTED]> wrote:
>
> > > My flaky webhost's MySQL process goes down randomly every few weeks.
>
> > > Cake doesn't throw an error, but instead gives a "Missing Table" error
> > > and displays a weird page (the layout nested 4 times).
>
> > > How and where would I test the db connection myself?
>
> > > (I want to show my own pretty "Temporarily down for maintenance" msg
> > > -- I know how to throw and show the error, I just don't know where to
> > > put the code that tests the connection)
>
> > > Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to