From Zen Cart(tm) Wiki
Jump to: navigation, search

Debug Error-Logging Utility to catch hidden PHP errors

See this forum post for more information on how to use this handy utility to catch hidden issues:

Script ends with a MySQL error

The first step to fixing this is often to find the failing query, and the following is one way to do that.

Open includes/classes/db/mysql/query_factory.php and replace

  function Execute($zf_sql, $zf_limit = false, $zf_cache = false, $zf_cachetime=0) {


  function Execute($zf_sql, $zf_limit = false, $zf_cache = false, $zf_cachetime=0) {
    $this->last_query = $zf_sql;

Then open includes/application_top.php and/or admin/includes/application_top.php, depending on where you need to debug, and add the following code to the beginning of the file, right after the license info:

function debug()
	global $db;
	if (is_object($db) && is_resource($db->link) && isset($db->last_query))
	// a connection to the DB has been made and a query has been executed
		$mysql_errno = mysql_errno($db->link);
		$mysql_error = mysql_error($db->link);
		if ($mysql_errno !== 0)
		// an error occured
			echo <<<ENDOFOUTPUT
		<div style="color: #fa7; background: #455; padding: 1em; text-align: left;">
			<p><strong>$mysql_errno : $mysql_error</strong></p>

That will display the last query when the script ends, but only if there was an error with the last executed query.