Post by Lembo » Mon Oct 14, 2019 8:11 am

Hello,
Sometimes my shared hosting get some issues with database connection and the connection fails,
and i get the following error on the index page
Notice: Undefined index: in /storage/modification/catalog/controller/startup/startup.php on line 109
Warning: fopen(/storage/logs/): failed to open stream: Is a directory in /system/library/log.php on line 22
Error: A theme has not been assigned to this store!
I want to configure the index page to show maintenance page or something like that when the database connection fails instead of showing this error to visitors
Is it possible?

New member

Posts

Joined
Wed Oct 17, 2018 9:56 am

Post by letxobnav » Mon Oct 14, 2019 9:18 am

The maintenance page logic also uses the database so that would not work without some changes.

You could create a static maintenance page and display that if the database is not connected.
In catalog/controller/startup/startup.php just behind the index function declaration:

Code: Select all

	// show static maintenance page when no database connection
	if (!$this->db->connected()) {
		error_log('Error (01): Database not connected, maintenance page shown.');
		ob_start();
		include(DIR_INCLUDES.'maintenance-en.html');
		$maintenance_page = ob_get_clean();
		echo $maintenance_page;
		exit();
	}

you just need to create the "maintenance-en.html" page and put it in a DIR_INCLUDES folder.
The best way to do that is to view-source on a normal page, copy the source and replace everything between the header and footer with your maintanance message and save it as a static html file. That way your maintenance page has the same look and feel as the others.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by Lembo » Tue Oct 15, 2019 9:01 pm

letxobnav wrote:
Mon Oct 14, 2019 9:18 am
The maintenance page logic also uses the database so that would not work without some changes.

You could create a static maintenance page and display that if the database is not connected.
In catalog/controller/startup/startup.php just behind the index function declaration:

Code: Select all

	// show static maintenance page when no database connection
	if (!$this->db->connected()) {
		error_log('Error (01): Database not connected, maintenance page shown.');
		ob_start();
		include(DIR_INCLUDES.'maintenance-en.html');
		$maintenance_page = ob_get_clean();
		echo $maintenance_page;
		exit();
	}

you just need to create the "maintenance-en.html" page and put it in a DIR_INCLUDES folder.
The best way to do that is to view-source on a normal page, copy the source and replace everything between the header and footer with your maintanance message and save it as a static html file. That way your maintenance page has the same look and feel as the others.
It gives me the following error
Fatal error: Uncaught Error: Call to undefined method DB\mPDO::connected() in /storage/modification/system/library/db.php:113

New member

Posts

Joined
Wed Oct 17, 2018 9:56 am

Post by Lembo » Tue Oct 15, 2019 9:28 pm

Lembo wrote:
Tue Oct 15, 2019 9:01 pm
letxobnav wrote:
Mon Oct 14, 2019 9:18 am
The maintenance page logic also uses the database so that would not work without some changes.

You could create a static maintenance page and display that if the database is not connected.
In catalog/controller/startup/startup.php just behind the index function declaration:

Code: Select all

	// show static maintenance page when no database connection
	if (!$this->db->connected()) {
		error_log('Error (01): Database not connected, maintenance page shown.');
		ob_start();
		include(DIR_INCLUDES.'maintenance-en.html');
		$maintenance_page = ob_get_clean();
		echo $maintenance_page;
		exit();
	}

you just need to create the "maintenance-en.html" page and put it in a DIR_INCLUDES folder.
The best way to do that is to view-source on a normal page, copy the source and replace everything between the header and footer with your maintanance message and save it as a static html file. That way your maintenance page has the same look and feel as the others.
It gives me the following error
Fatal error: Uncaught Error: Call to undefined method DB\mPDO::connected() in /storage/modification/system/library/db.php:113
Fixed by adding
public function isConnected() {
return $this->adaptor->isConnected();
}
to system/library/db.php just before public function connected()
also changed your code to
if (!$this->db->isConnected()) {
error_log('Error (01): Database not connected, maintenance page shown.');
ob_start();
include(DIR_STORAGE.'maintenance-en.html');
$maintenance_page = ob_get_clean();
echo $maintenance_page;
exit();
}
Note : added maintenance-en.html to storage directory
Thank you still waiting for database faulty to test it's functioning

New member

Posts

Joined
Wed Oct 17, 2018 9:56 am
Who is online

Users browsing this forum: nonnedelectari and 399 guests