Page 1 of 1

[REQUEST] 'Friendly' Database Errors

Posted: Thu Mar 22, 2012 7:44 am
by bbcentral
When an OpenCart store is having MySQL connection issues (such as too many connections etc), this causes visitors to see unfriendly error messages.

By default, in:
/system/database/mysql.php
if the MySQL connection fails, it simply runs this code:

Code: Select all

public function __construct($hostname, $username, $password, $database) {
	if (!$this->link = mysql_connect($hostname, $username, $password)) {
		trigger_error('Error: Could not make a database link using ' . $username . '@' . $hostname);
	}

	if (!mysql_select_db($database, $this->link)) {
		trigger_error('Error: Could not connect to database ' . $database);
	}
(from the latest SVN revision as of March 3 2012)

So if MySQL is temporarily overloaded, customers will see:
"Error: Could not make a database link using mystore@localhost"

Instead of displaying this to the customers, it would be much better if it displayed a friendly error message, perhaps something like:
"We are currently experiencing technical difficulties, please click here to try again in a few seconds. If you continue to experience issues, please contact us: sales@mystore"

The actual original error message will be logged on the server anyway to allow the administrators to troubleshoot the problem anyway.

Also, there's no point trying to close a MySQL connection that doesn't exist, all you're doing is doubling up the errors in the logfile.

Perhaps this:

Code: Select all

public function __destruct() {
	mysql_close($this->link);
}
could become this:

Code: Select all

public function __destruct() {
	if($this->link) {
		mysql_close($this->link);
	}
}

Re: [REQUEST] 'Friendly' Database Errors

Posted: Mon Apr 02, 2012 10:15 pm
by exactweb
All valid points