Re: getting database connection to fail gracefully

From: Date: Wed, 22 Jan 2003 11:25:21 +0000
Subject: Re: getting database connection to fail gracefully
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-132574@lists.php.net to get a copy of this message
On Wednesday 22 January 2003 19:11, Andy Clarke wrote: > Is there a way to get a database query to fail gracefully, so that rather > than calling Die(), it can work around the problem? In other words, to do > something like: > > if (mssql_connect($sDBhostname,$sDBusername,$sDBpassword)) { > // connection ok - work with it > } else { > // database down - work around it > } > // continue with rest of page > > Rather than using the following, which causes the page to quit in mid flow: > > mssql_connect($sDBhostname,$sDBusername,$sDBpassword) or die("DATABASE > FAILED TO RESPOND."); Obviously, quite simply, don't use die(). Instead call a function which can handle it: It really depends on what your needs are and what the page does. The most simple case is print a message informing the user that "the database is down please try again later" (or words to that effect). At the same time you would log this failure (to a log file) and/or email someone responsible who can deal with it. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Traveling through hyperspace isn't like dusting crops, boy. -- Han Solo */

« previous php.general (#132574) next »