Jump to content



Issue Information

  • #000564

  • 0 - None Assigned

  • New

  • 2.3.3

  • -

Issue Confirmations

  • Yes (0)No (0)
Photo

Where is the mysql error log, tep_db_error not logged? error log, database.php, mysql

Posted by Gergely on 20 January 2013 - 13:09

Hi,

when use tep_db_error() function in osCommerce store, the result display only on browser window but would be very usefull to see the competent persons and not vendors or customers.

There are two possibilities.
1. Send an mail to store owner with error message.
2. Write error message to the error_log file

Mysql error log not write the error into the default log file so this is unusless.

I resolved this pb by this

function tep_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') {
global $$link;
if (USE_PCONNECT == 'true') {
	 $$link = mysql_pconnect($server, $username, $password);
} else {
	 $$link = mysql_connect($server, $username, $password);
}
mysql_query("set character set utf-8", $$link);
if ($$link) {
	 mysql_select_db($database);
/* Alert by mail if there is a problem with the database*/
} else {
	 require (DIR_WS_CLASSES . 'phpmailer/class.phpmailer.php');
	 $mail = new PHPMailer(true);
	 $mail->IsMAIL();
	 $mail->SetFrom('myemail.com','oscommerce Administrator');
	 $mail->AddAddress('myemail.com','Oscommerce Administrator');
	 $mail->Subject='Connexion error Oscommerce Database';
	 $mail->AltBody='Please verify you website, an error has been detected on your Database :'. date ('G') . '/' . date('m').'/'.date('Y') . ' on the domain ' . HTTP_SERVER;
// verification
	 $mail->IsHTML(false);
	 if(!$mail->Send()){
	 echo $mail->ErrorInfo; //Display error message
	 } else {
	 echo '<br /><br />An alert mail was sent to the administrator<br /><br />';
	 }
	 $mail->SmtpClose();
	 unset($mail);
	 exit;
}
/* End Alert by mail if there is a problem with the database*/

Edited by Gyakutsuki, 20 January 2013 - 16:37.


why dont you use built in functions? The hard coding not recommended in bug fixes. This problem could be fix only with configuration file cache. I dont now what sould I do.
The solution does not work hard coding or without cache.
At this moment I had to install cache contribution for use my solution.

Here is my code:
function tep_db_error($query, $errno, $error) {
if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
	 error_log('QUERY ' . $errno . ' - ' . $error . "\n\n" . $query . "\n" . 'file: ' . __FILE__ . ' line: ' . __LINE__ . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
} elseif (defined('MYSQL_ERROR_EMAIL_REPORT') && (MYSQL_ERROR_EMAIL_REPORT == 'true')) {
	 error_log('QUERY ' . $errno . ' - ' . $error . "\n\n" . $query . "\n" . 'file: ' . __FILE__ . ' line: ' . __LINE__ . "\n", 1, STORE_OWNER_EMAIL_ADDRESS);
}
die('<font color="#000000"><strong>' . $errno . ' - ' . $error . '<br /><br />' . $query . '<br /><br /><small><font color="#ff0000">[TEP STOP]</font></small><br /><br /></strong></font>');
}

in connection controll:
if ($$link) {
		 mysql_select_db($database);
/* Alert by mail if there is a problem with the database*/
} else {
tep_db_error('Open Connection', '2006', 'MySQL server has gone away');
}

Edited by Gergely, 21 January 2013 - 07:22.


I just insert a phpmailer and if the mysql connexion is broken. It works long time and I haven't never been a problem.
The pb with Oscommerce, there is no cache with the configuration database (an upgrade will became on the next osc version andwill increase the performance), I don't test if I put the email in the language files. if it's work., it's better to insert in the language or configure.php.
For the cache, the administrator must actived ! I don't if it's the best way to resolve the pb

The dashboard modules would be the best soulution against the email. I have made an universal error log viewer for administration. Backported from v3alfa5. A simple user php error message will work without any SQL or predefined constans.

https://github.com/t...3af730cfd255b07

  function tep_db_error($query, $errno, $error) {
    error_log('SQL ERROR ' . $errno . ' - ' . $error . "\n\n" . $query, 0 );
    die('<font color="#000000"><b>' . $errno . ' - ' . $error . '<br><br>' . $query . '<br><br><small><font color="#ff0000">[TEP STOP]</font></small><br><br></b></font>');
  }


yes I see that, it's good idea, but the administraot must to come in administration panel. It's not all the days.
To receive an email, it'a warning to resolve the problem shortly else the administror dose'nt know the problem on his website.