Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Automatice Redirect if Database is down


netfrugal

Recommended Posts

There has been a few cases when my db has been down for maintenance reasons. I have been attempting to put a redirect into the code that is triggered if there is no successful db connection.

 

I believe in functions/database.php is the answer, but I am shooting in the dark.

 

Currently line 16 states this:

 

if (USE_PCONNECT == 'true') {

$$link = mysql_pconnect($server, $username, $password) or die(mysql_error());

} else {

$$link = mysql_connect($server, $username, $password) or die(mysql_error());

}

 

I was thinking that the change needs to be after like this:

 

if (USE_PCONNECT == 'true') {

$$link = mysql_pconnect($server, $username, $password) or die(mysql_error());

} else {

$$link = mysql_connect($server, $username, $password) or die(mysql_error());

} else {

'header("www.yahoo.com")';

}

 

 

Of course it is not resolving and I am not at all sure if I am even looking in the right place.

 

Any help would be appreciated!

 

Marc

Link to comment
Share on other sites

There has been a few cases when my db has been down for maintenance reasons. I have been attempting to put a redirect into the code that is triggered if there is no successful db connection.

 

I believe in functions/database.php is the answer, but I am shooting in the dark.

 

Currently line 16 states this:

 

if (USE_PCONNECT == 'true') {

$$link = mysql_pconnect($server, $username, $password) or die(mysql_error());

} else {

$$link = mysql_connect($server, $username, $password) or die(mysql_error());

}

 

I was thinking that the change needs to be after like this:

 

if (USE_PCONNECT == 'true') {

$$link = mysql_pconnect($server, $username, $password) or die(mysql_error());

} else {

$$link = mysql_connect($server, $username, $password) or die(mysql_error());

} else {

'header("www.yahoo.com")';

}

 

 

Of course it is not resolving and I am not at all sure if I am even looking in the right place.

 

Any help would be appreciated!

 

Marc

 

What kind of errors do you get when you can't connect to the database.

You might be able to handle these errors with redirects

I have this in a .htaccess file for when 404 errors crop up and people access pages that are no longer up on my site.

 

in my .htaccess file in the root of my site the line :

ErrorDocument 404 /errors/notfound.html

does this for me.

Backup before making changes. Backup before making changes! Backup before making changes!!

 

You did do a backup? eh?

Link to comment
Share on other sites

What kind of errors do you get when you can't connect to the database.

You might be able to handle these errors with redirects

I have this in a .htaccess file for when 404 errors crop up and people access pages that are no longer up on my site.

 

in my .htaccess file in the root of my site the line :

ErrorDocument 404 /errors/notfound.html

does this for me.

 

application_top.php

 

// make a connection to the database... now

tep_db_connect() or die('Unable to connect to database server!');

 

change to:

 

 

// make a connection to the database... now

if (!tep_db_connect()) header('Location: www.yahoo.com');

Treasurer MFC

Link to comment
Share on other sites

application_top.php

 

// make a connection to the database... now

tep_db_connect() or die('Unable to connect to database server!');

 

change to:

// make a connection to the database... now

if (!tep_db_connect()) header('Location: www.yahoo.com');

 

 

 

Thanks for the advice. But this didn't work either. I get this error:

 

1046 - No database selected

 

select configuration_key as cfgKey, configuration_value as cfgValue from configuration

 

[TEP STOP]

 

 

I didn't shut off the db server. I only changed the db name in configuration.php. Is that what you did?

Link to comment
Share on other sites

Thanks for the advice. But this didn't work either. I get this error:

 

1046 - No database selected

 

select configuration_key as cfgKey, configuration_value as cfgValue from configuration

 

[TEP STOP]

I didn't shut off the db server. I only changed the db name in configuration.php. Is that what you did?

you don't change your store's server configuration. You should restore your configure.php file. It was said to change the application_top.php file I believe.

Link to comment
Share on other sites

you don't change your store's server configuration. You should restore your configure.php file. It was said to change the application_top.php file I believe.

 

Yes, I know the change was for application_top.php

 

The point I was making is if the db server fails, or the settings in configuration.php are wrong - then an automatic redirect to a different page would be triggered.

Link to comment
Share on other sites

for the connect you can do your error handling or whatever here in application_top.php

 

// make a connection to the database... now

tep_db_connect() or die('Unable to connect to database server!');

 

so instead of the "or die" you do your redirect there.

Link to comment
Share on other sites

for the connect you can do your error handling or whatever here in application_top.php

 

// make a connection to the database... now

tep_db_connect() or die('Unable to connect to database server!');

 

so instead of the "or die" you do your redirect there.

 

 

You are correct Automatice. I was having the problems with making the redirect script to function properly. It was just getting the syntax correct on my part.

 

It works now. here is the code:

 

.... or die(Header("Location:http://www.domain.com"));

Link to comment
Share on other sites

sorry I though you were looking just for the place to do it.

 

you can add a temporary redirect

if( !tep_db_connect() ) {
header("HTTP/1.1 307 Temporary Redirect");
header("Location:http://www.domain.com");
exit;
}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...