Jump to content

Handling db errors


slarson20

Recommended Posts

Whats the best way to handle database errors.

 

I been using ob_start() stuff to run the code and if a database connection error occurs an variable $error turns to 1 and it displays the error code instead of the normal page that should be displayed when no errors occur.

 

It works but I want to know if there is any better way to manage a db connection error while running a script.

 

Also, how do you manage a problem when like 3 queries are ran to setup a new user account and the last one fails because the db connection drops or something, how would you go about handling a 2/3 query successful?

 

I'm really stuck on how to manage errors if a db connection fails after the first connection is successful.

Link to comment
Share on other sites

Lets say you use a template object to get the title, and that query fails, then what?

 

I will sometimes build sites with different "levels" of errors. Some errors are minor and you can display the page as normal with the error displayed. However, there are also critical errors that prevent you from even gathering enough data to put together a "pretty" error page. For the latter you could have a flat HTML error page when that occurs.

 

I have noticed that this site display an all white page with a short message when DB connectivity is down. Since it cannot access the database there isn't much use in trying to show the normal page with the pretty colors and such. Even something such as the menu at the top would be dynamic based on the user's permissions (which are stored in the DB).

 

So, make a decision on how you want to handle. If you can't pull a template do you even continue trying to display a "pretty" page, do you use a default template, or what?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.