Redirect if unable to connect to database?

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
Post Reply
Nate
Posts: 42
Joined: Sun 11. Apr 2004, 18:26

Redirect if unable to connect to database?

Post by Nate »

Hello, today my database is down (due to my web host). I get the following error message when I try to access the phpWCMS front-end:

Code: Select all

Warning: mysql_pconnect(): Lost connection to MySQL server during query in /home/www.mydomain.com/include/inc_lib/default.inc.php on line 25
Error while trying to connect to mysql.mydomain.com
My question is, is there any way I can have WCMS redirect the viewer to another url when this happens, instead of displaying the error message?
To fathom hell or soar angelic...
User avatar
Oliver Georgi
Site Admin
Posts: 9917
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

OK change your default.inc.php based on the following code:

Code: Select all

<?php
/*************************************************************************************
   Copyright notice
   
   (c) 2002-2004 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
 
   This script is part of PHPWCMS. The PHPWCMS web content management system is
   free software; you can redistribute it and/or modify it under the terms of
   the GNU General Public License as published by the Free Software Foundation;
   either version 2 of the License, or (at your option) any later version.
  
   The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
   A copy is found in the textfile GPL.txt and important notices to the license 
   from the author is found in LICENSE.txt distributed with these scripts.
  
   This script is distributed in the hope that it will be useful, but WITHOUT ANY 
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
   PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 
   This copyright notice MUST APPEAR in all copies of the script!
*************************************************************************************/

// build the database table prepend part
define ("DB_PREPEND", ($phpwcms["db_prepend"]) ? $phpwcms["db_prepend"]."_" : "");

// define the real path of the phpwcms installation
// important to script that must know the real path to files or something else
define ("PHPWCMS_ROOT", preg_replace('/\/$/', '', $_SERVER['DOCUMENT_ROOT']).(($phpwcms["root"]) ? "/".$phpwcms["root"] : "") );   // DOCUMENT_ROOT + phpwcms directory

$phpwcms["root"]		 = ($phpwcms["root"]) ? $phpwcms["root"]."/" : "";

$phpwcms["file_path"]    = "/".$phpwcms["file_path"]."/" ;  // "/phpwcms_filestorage/"
$phpwcms["file_tmp"]     = $phpwcms["file_tmp"]."/"      ;  // "phpwcms_tmp/"
$phpwcms["templates"]    = "/".$phpwcms["templates"]."/" ;  // "/phpwcms_template/"
$phpwcms["dir_thlist"]   = $phpwcms["dir_thlist"]."/"    ;  // "thumb_list/"
$phpwcms["dir_preview"]  = $phpwcms["dir_preview"]."/"   ;  // "thumb_preview/"
$phpwcms["content_path"] = $phpwcms["content_path"]."/"  ;  // "content/"
$phpwcms["cimage_path"]  = $phpwcms["cimage_path"]."/"   ;  // "images/"
$phpwcms["ftp_path"]     = "/".$phpwcms["ftp_path"]."/"  ;  // "/phpwcms_ftp/"

// check which function should be used to create thumbnail images
// and if ImageMagick check if enabled or 1 or located at give path
if($phpwcms["imagick_path"]) {
	$phpwcms["imagick_path"] = $phpwcms["imagick_path"].'/';
	$phpwcms["imagick_path"] = str_replace("\\", "/", $phpwcms["imagick_path"]);
	$phpwcms["imagick_path"] = str_replace("//", "/", $phpwcms["imagick_path"]);
	define ("IMAGICK_PATH", $phpwcms["imagick_path"]);
} else {
	define ("IMAGICK_PATH", "");
}
define ("IMAGICK_ON", intval($phpwcms["imagick"]));
define ("GD2_ON", intval($phpwcms["use_gd2"]));
define ("PHPWCMS_CHARSET", (($phpwcms["charset"]) ? $phpwcms["charset"] : "iso-8859-1"));

if(!$phpwcms['SMTP_MAILER']) $phpwcms['SMTP_MAILER'] = 'mail';
if(!$phpwcms['SMTP_FROM_EMAIL']) $phpwcms['SMTP_FROM_EMAIL'] = $phpwcms["admin_email"];


// open the connection to MySQL database
$is_mysql_error = 0;
if($phpwcms["db_pers"] == 1) {
	$db = @mysql_pconnect($phpwcms["db_host"], $phpwcms["db_user"], $phpwcms["db_pass"]) or ($is_mysql_error = 1);
} else {
	$db = @mysql_connect($phpwcms["db_host"], $phpwcms["db_user"], $phpwcms["db_pass"]) or ($is_mysql_error = 1);
}
@mysql_select_db($phpwcms["db_table"],$db) or ($is_mysql_error = 1);

if($is_mysql_error) {
	header('Location: '.$phpwcms['site'].$phpwcms['root'].'dbdown.php');
	exit();
}

$phpwcms["version"] = "1.1-RC4 22-06-2004";

?>
All you have to do is delete the first lines where it trys to connect to the database and add the last lines at same place as listed above.

Create a new file "dbdown.php" in phpwcms root.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
Nate
Posts: 42
Joined: Sun 11. Apr 2004, 18:26

Post by Nate »

Thank you very much Oliver; I'm going to try it out now.
To fathom hell or soar angelic...
Post Reply