Jump to content

[SOLVED] function to redirect site to error page


mmarif4u

Recommended Posts

Hi all.

I have site where some time i update the database details according to server and my local pc.

Now i want a function that will redirect the user  if database name or username or password is wrong.

i dont want that the site show in the middle of page " cannot connect to database",

i want that i redirect the user if some problem occur in the database config.

Hope some will have a good idea.

 

Thanks

Link to comment
Share on other sites

The text book way to connect, with an error.

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
   die('Could not connect: ' . mysql_error());
}

 

What you can use instead:

$link = @mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
   header('Location: http://www.google.com');
}

Replace google with where you want it to go.

 

There are many ways to solve the deeper problem here. One way is to have a "sql.php" file on each server, with the "mysql_connect" and "mysql_select_db" functions filled out for that server. You can also do if/else matches against the $_SERVER vars.

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.