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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.