Skip to main content
Home
Live to Learn!

Main navigation

  • Home
  • Learn
    • FoxPro
    • MS-DOS
    • C PRG
    • Java
    • ASP
    • Ruby on Rails
    • ASP.NET
    • E-Books
    • Exam Preparation
    • Tools
  • Blog
  • Forums
  • Contact
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Blog

Redirect when sql server fails

By admin , 26 March, 2010

Some time in Linux based (Free) hosting services the server down occurs only to mysql server. But the apache server works well.

In that time if you are using database connectivity in php code, it will expose error message to the end user.

There is a way to hide the error message and redirect the user to alternate website if you want.

Create a separate file to connect to the mysql server with following script. So on any page you want to connect to the server, just include that script.

The error page is “error/database.php”. As long as you use this script before any output it’s guaranteed to display only the error page when the database fails. In this file you can include script to redirect the user to alternate website you have.

 

For example, you can let the viewer to visit your blogger blog at the time of your site fails to load.

<?php
@mysql_connect(“server”, â€œusername”, â€œpassword”) or databasefailure();
@mysql_select_db(“dbname”) or databasefailure();

function databasefailure() {
include â€œ{$_SERVER[“DOCUMENT_ROOT”]}/error/database.php”;
exit;
}
?>

Also, notice the ‘@’ in front of those two lines. Using this character will cause the line to become silent. No run-time errors will be displayed for that line, at all. (Of course syntax errors are still displayed.) Be careful with this though, it will hide any warning or error for that line, which can cause a lot of headache when debugging.

Thanks for marshian at X10

Category
How to
Tags
SQL Server

Comments

  • Add new comment

Featured Blog Posts

Convert Currency in Number to Words (Indian Rupees) - MS Excel
Foxpro Tutorial and Programs
Convert Currency in Number to Words in MS Word
Convert Currency in Number to Words (Indian Rupees) - Version 2
Best way to Use Rupee Symbol in Windows – Easy steps
Convert Currency in Number to Words - MS Access
Creating All in One Windows XP DVD with all Important Applications
RSS feed

© 2009-2025 Live to Learn.In

Terms of Use | Privacy Policy