Home > CRE Loaded > Installing “Output Queries Debug” in CRE Loaded 6.4 PCI

Installing “Output Queries Debug” in CRE Loaded 6.4 PCI

November 1st, 2009 Leave a comment Go to comments

Output Queries Debug is very useful contribution for osCommerce. This contribution captures each query used to construct a page and can be output if desired. This information can be very useful for developers working on CRE Loaded performance optimization. To see more details about the contribution please refer to this page.

In this post we will be installing on CRE Loaded PCI 6.4 PRO. We will be using Runtime Code Inclusion (RCI) feature for installing the contribution. For details about RCI please refer to CRE loaded forums or any where ever you can find.

It is always a good idea to backup your files before making any changes. Unless you feel comfortable do not make the changes on live site.

Step One: Changing tep_db_query function
Open file includes/functions/database.php and

Find:

if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
$page_name = $_SERVER['SCRIPT_FILENAME'];
$page_name = str_replace('\', '/', $page_name);
$page_name = str_replace('//', '/', $page_name);
$i = strrpos($page_name, '/');
$page_name = substr($page_name, $i+1);
error_log('QUERY - ' . $page_name . ':'. "\n" . $query . "\n", 3, DIR_FS_CATALOG . STORE_PAGE_PARSE_TIME_LOG);
$sql_start = microtime(true);
}

After above code Add following

// queries_debug-v1.7
$query_start = microtime();

After:

$result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error());

Add:

// start queries_debug-v1.7
global $debug;
if ((DISPLAY_QUERIES == 'true') || (DISPLAY_PAGE_PARSE_TIME == 'true')){
$_start = explode(' ', $query_start);
$_end = explode(' ', microtime());
$_time = number_format(($_end[1] + $_end[0]) - ($_start[1] + $_start[0]), 6);

$debug['QUERIES'][] = $query;
$debug['TIME'][] = $_time;
}
// end queries_debug-v1.7

Step Two:
Create a new php file debug_applicationbottom_bottom.php in /includes/runtime/applicationbottom/ and put following code in the created file

<?php
global $debug;
if (DISPLAY_PAGE_PARSE_TIME == ‘true’) {
$time_start = explode(‘ ‘, PAGE_PARSE_START_TIME);
$time_end = explode(‘ ‘, microtime());
$parse_time = number_format(($time_end[1] + $time_end[0] – ($time_start[1] + $time_start[0])), 3);
echo ‘<div align=”center”><span>’ . $parse_time . ‘ – ‘ . sizeof($debug['QUERIES']) . ‘</span></div>’;
if (DISPLAY_QUERIES == ‘true’) {
echo ‘<b>QUERY DEBUG:</b><pre>’;
print_r($debug);
echo ‘</pre><hr>’;
echo ‘<b>SESSION:</b><pre>’;
print_r($_SESSION);
echo ‘</pre><hr>’;
echo ‘<b>COOKIE:</b><pre>’;
print_r($_COOKIE);
echo ‘</pre><b>POST:</b><pre>’;
print_r($_POST);
echo ‘</pre><hr>’;
echo ‘<b>GET:</b><pre>’;
print_r($_GET);
echo ‘</pre>’;
} # END if request
}
unset($debug);
?>

Step Three: adding configuration
Run following sql statement on your database through phpmyadmin, command line or any MySQL other interface. This statement will allow you to turn on or off the queries through the admin panel:

INSERT INTO configuration ( configuration_id , configuration_title , configuration_key ,
configuration_value , configuration_description , configuration_group_id , sort_order ,
last_modified , date_added , use_function , set_function )
VALUES ( '', 'Display Database Queries', 'DISPLAY_QUERIES', 'true',
'Display COOKIE, SESSION, POST, and GET data in the footer', '10', '6', NOW( ) , NOW( ) ,
NULL , 'tep_cfg_select_option(array(''true'', ''false''),' );

And that’s it we are done with the installation. Browse to home page of your CRE Loaded installation to see if its working. You can turn on/off the queries information displayed at bottom of the page from admin » Logging » Display Database Queries menu.

Categories: CRE Loaded Tags:
  1. No comments yet.
  1. No trackbacks yet.