Example #1
0
 function clearsql()
 {
     $perf_table = adodb_perf::table();
     // using the naive "delete from $perf_table where created<".$this->conn->sysTimeStamp will cause the table to lock, possibly
     // for a long time
     $sql = "DECLARE cnt pls_integer;\r\nBEGIN\r\n\tcnt := 0;\r\n\tFOR rec IN (SELECT ROWID AS rr FROM {$perf_table} WHERE created<SYSDATE) \r\n\tLOOP\r\n\t  cnt := cnt + 1;\r\n\t  DELETE FROM {$perf_table} WHERE ROWID=rec.rr;\r\n\t  IF cnt = 1000 THEN\r\n\t  \tCOMMIT;\r\n\t\tcnt := 0;\r\n\t  END IF;\r\n\tEND LOOP;\r\n\tcommit;\r\nEND;";
     $ok = $this->conn->Execute($sql);
 }
Example #2
0
function &adodb_log_sql(&$conn, $sql, $inputarr)
{
    /**
     OXID changes - create separate mysql connection for logging for not loosing info from last query (R)
    */
    $_logSqlDbInstance = $conn->_logSqlDbInstance;
    $perf_table = adodb_perf::table();
    $conn->_logsql = false;
    // replaces setting ::fnExecute=false in ADOdb
    $t0 = microtime();
    $rs =& $conn->Execute($sql, $inputarr);
    $t1 = microtime();
    $conn->_logsql = true;
    // reverse setting ::_logsql=false
    if (!$_logSqlDbInstance) {
        $myConfig = oxConfig::getInstance();
        $conn->_logSqlDbInstance = $_logSqlDbInstance =& NewADOConnection($myConfig->getConfigParam("dbType"));
        $_logSqlDbInstance->_connect($conn->host, $conn->username, $conn->password, $conn->database, false, true);
    }
    if (!empty($conn->_logsql)) {
        //$conn->_logsql = false; // disable logsql error simulation
        $dbT = $conn->dbtype;
        $a0 = explode(' ', $t0);
        $a0 = (double) $a0[1] + (double) $a0[0];
        $a1 = explode(' ', $t1);
        $a1 = (double) $a1[1] + (double) $a1[0];
        $time = $a1 - $a0;
        if (!$rs) {
            $errM = $conn->ErrorMsg();
            $errN = $conn->ErrorNo();
            $tracer = substr('ERROR: ' . htmlspecialchars($errM), 0, 250);
        } else {
            $tracer = '';
            $errM = '';
            $errN = 0;
        }
        if (isset($_SERVER['HTTP_HOST'])) {
            $tracer .= '<br>' . $_SERVER['HTTP_HOST'];
            if (isset($_SERVER['PHP_SELF'])) {
                $tracer .= $_SERVER['PHP_SELF'];
            }
        } elseif (isset($_SERVER['PHP_SELF'])) {
            $tracer .= '<br>' . $_SERVER['PHP_SELF'];
        }
        // OXID - added backtrace
        $_aTrace = debug_backtrace();
        $_sTrace = '';
        foreach ($_aTrace as $_trace) {
            $_sTrace .= "{$_trace['file']} - {$_trace['function']}:{$_trace['line']}\n";
        }
        $tracer .= "\n\nBacktrace:\n" . $_sTrace;
        $tracer = (string) substr($tracer, 0, 5000);
        if (is_array($inputarr)) {
            if (is_array(reset($inputarr))) {
                $params = 'Array sizeof=' . sizeof($inputarr);
            } else {
                // Quote string parameters so we can see them in the
                // performance stats. This helps spot disabled indexes.
                $xar_params = $inputarr;
                foreach ($xar_params as $xar_param_key => $xar_param) {
                    if (gettype($xar_param) == 'string') {
                        $xar_params[$xar_param_key] = '"' . $xar_param . '"';
                    }
                }
                $params = implode(', ', $xar_params);
                if (strlen($params) >= 3000) {
                    $params = substr($params, 0, 3000);
                }
            }
        } else {
            $params = '';
        }
        if (is_array($sql)) {
            $sql = $sql[0];
        }
        $arr = array('b' => strlen($sql) . '.' . crc32($sql), 'c' => substr($sql, 0, 3900), 'd' => $params, 'e' => $tracer, 'f' => adodb_round($time, 6));
        //$saved = $_logSqlDbInstance->debug;
        //$_logSqlDbInstance->debug = 0;
        $d = $conn->sysTimeStamp;
        if (empty($d)) {
            $d = date("'Y-m-d H:i:s'");
        }
        /*
        // OCI/Informix/ODBC_MSSQL - not sure if/how available in adodb-lite so I've commented out the section for now - (Pádraic)
        */
        /*if ($dbT == 'oci8' && $dbT != 'oci8po')
                {
                    $isql = "insert into $perf_table values($d,:b,:c,:d,:e,:f)";
                }
                elseif($dbT == 'odbc_mssql' || $dbT == 'informix')
                {
                    $timer = $arr['f'];
                    if ($dbT == 'informix') $sql2 = substr($sql2,0,230);
        
                    $sql1 = $conn->qstr($arr['b']);
                    $sql2 = $conn->qstr($arr['c']);
                    $params = $conn->qstr($arr['d']);
                    $tracer = $conn->qstr($arr['e']);
        
                    $isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values($d,$sql1,$sql2,$params,$tracer,$timer)";
                    if ($dbT == 'informix') $isql = str_replace(chr(10),' ',$isql);
                    $arr = false;
                } else {*/
        $isql = "insert into {$perf_table} (created,sql0,sql1,params,tracer,timer) values( {$d},?,?,?,?,?)";
        //}
        // OXID change - added try catch wrapping
        try {
            $ok = $_logSqlDbInstance->Execute($isql, $arr);
        } catch (Exception $e) {
            $ok = false;
        }
        //$_logSqlDbInstance->debug = $saved;
        if ($ok) {
            //$_logSqlDbInstance->_logsql = true;
        } else {
            $err2 = $_logSqlDbInstance->ErrorMsg();
            //$_logSqlDbInstance->_logsql = true; // enable logsql error simulation
            $perf =& NewPerfMonitor($_logSqlDbInstance);
            if ($perf) {
                if ($perf->CreateLogTable()) {
                    $ok = $_logSqlDbInstance->Execute($isql, $arr);
                }
            } else {
                $ok = $_logSqlDbInstance->Execute("create table {$perf_table} (\r\n                created varchar(50),\r\n                sql0 varchar(250),\r\n                sql1 varchar(4000),\r\n                params varchar(3000),\r\n                tracer varchar(5000),\r\n                timer decimal(16,6))");
            }
            /*if (!$ok) {
                  ADOConnection::outp( "<p><b>LOGSQL Insert Failed</b>: $isql<br>$err2</p>");
                  $conn->_logsql = false;
              }*/
        }
        //$conn->_errorMsg = $errM;
        //$conn->_errorCode = $errN;
    }
    return $rs;
}
Example #3
0
 function HealthCheck($cli = false)
 {
     $this->conn->Execute('dbcc traceon(3604)');
     $html = adodb_perf::HealthCheck($cli);
     $this->conn->Execute('dbcc traceoff(3604)');
     return $html;
 }
Example #4
0
 function UI($pollsecs = 5)
 {
     global $ADODB_LOG_CONN;
     $perf_table = adodb_perf::table();
     $conn = $this->conn;
     $app = $conn->host;
     if ($conn->host && $conn->database) {
         $app .= ', db=';
     }
     $app .= $conn->database;
     if ($app) {
         $app .= ', ';
     }
     $savelog = $this->conn->LogSQL(false);
     $info = $conn->ServerInfo();
     if (isset($_GET['clearsql'])) {
         $this->clearsql();
     }
     $this->conn->LogSQL($savelog);
     // magic quotes
     if (isset($_GET['sql']) && get_magic_quotes_gpc()) {
         $_GET['sql'] = $_GET['sql'] = str_replace(array("\\'", '\\"'), array("'", '"'), $_GET['sql']);
     }
     if (!isset($_SESSION['ADODB_PERF_SQL'])) {
         $nsql = $_SESSION['ADODB_PERF_SQL'] = 10;
     } else {
         $nsql = $_SESSION['ADODB_PERF_SQL'];
     }
     $app .= $info['description'];
     if (isset($_GET['do'])) {
         $do = $_GET['do'];
     } else {
         if (isset($_POST['do'])) {
             $do = $_POST['do'];
         } else {
             if (isset($_GET['sql'])) {
                 $do = 'viewsql';
             } else {
                 $do = 'stats';
             }
         }
     }
     if (isset($_GET['nsql'])) {
         if ($_GET['nsql'] > 0) {
             $nsql = $_SESSION['ADODB_PERF_SQL'] = (int) $_GET['nsql'];
         }
     }
     echo "<title>ADOdb Performance Monitor on {$app}</title><body bgcolor=white>";
     if ($do == 'viewsql') {
         $form = "<td><form># SQL:<input type=hidden value=viewsql name=do> <input type=text size=4 name=nsql value={$nsql}><input type=submit value=Go></td></form>";
     } else {
         $form = "<td>&nbsp;</td>";
     }
     $allowsql = !defined('ADODB_PERF_NO_RUN_SQL');
     global $ADODB_PERF_MIN;
     $app .= " (Min sql timing \$ADODB_PERF_MIN={$ADODB_PERF_MIN} secs)";
     if (empty($_GET['hidem'])) {
         echo "<table border=1 width=100% bgcolor=lightyellow><tr><td colspan=2>\n\t<b><a href=http://adodb.sourceforge.net/?perf=1>ADOdb</a> Performance Monitor</b> <font size=1>for {$app}</font></tr><tr><td>\n\t<a href=?do=stats><b>Performance Stats</b></a> &nbsp; <a href=?do=viewsql><b>View SQL</b></a>\n\t &nbsp; <a href=?do=tables><b>View Tables</b></a> &nbsp; <a href=?do=poll><b>Poll Stats</b></a>", $allowsql ? ' &nbsp; <a href=?do=dosql><b>Run SQL</b></a>' : '', "{$form}", "</tr></table>";
     }
     switch ($do) {
         default:
         case 'stats':
             if (empty($ADODB_LOG_CONN)) {
                 echo "<p>&nbsp; <a href=\"?do=viewsql&clearsql=1\">Clear SQL Log</a><br>";
             }
             echo $this->HealthCheck();
             //$this->conn->debug=1;
             echo $this->CheckMemory();
             global $ADODB_LOG_CONN;
             break;
         case 'poll':
             $self = htmlspecialchars($_SERVER['PHP_SELF']);
             echo "<iframe width=720 height=80% \n\t\t\t\tsrc=\"{$self}?do=poll2&hidem=1\"></iframe>";
             break;
         case 'poll2':
             echo "<pre>";
             $this->Poll($pollsecs);
             break;
         case 'dosql':
             if (!$allowsql) {
                 break;
             }
             $this->DoSQLForm();
             break;
         case 'viewsql':
             if (empty($_GET['hidem'])) {
                 echo "&nbsp; <a href=\"?do=viewsql&clearsql=1\">Clear SQL Log</a><br>";
             }
             echo $this->SuspiciousSQL($nsql);
             echo $this->ExpensiveSQL($nsql);
             echo $this->InvalidSQL($nsql);
             break;
         case 'tables':
             echo $this->Tables();
             break;
     }
     global $ADODB_vers;
     echo "<p><div align=center><font size=1>{$ADODB_vers} Sponsored by <a href=http://phplens.com/>phpLens</a></font></div>";
 }
function &adodb_log_sql(&$conn, $sql, $inputarr)
{
    $perf_table = adodb_perf::table();
    $conn->_logsql = false;
    // replaces setting ::fnExecute=false in ADOdb
    $t0 = microtime();
    $rs =& $conn->Execute($sql, $inputarr);
    $t1 = microtime();
    $conn->_logsql = true;
    // reverse setting ::_logsql=false
    if (!empty($conn->_logsql)) {
        $conn->_logsql = false;
        // disable logsql error simulation
        $dbT = $conn->dbtype;
        $a0 = split(' ', $t0);
        $a0 = (double) $a0[1] + (double) $a0[0];
        $a1 = split(' ', $t1);
        $a1 = (double) $a1[1] + (double) $a1[0];
        $time = $a1 - $a0;
        if (!$rs) {
            $errM = $conn->ErrorMsg();
            $errN = $conn->ErrorNo();
            $tracer = substr('ERROR: ' . htmlspecialchars($errM), 0, 250);
        } else {
            $tracer = '';
            $errM = '';
            $errN = 0;
        }
        if (isset($_SERVER['HTTP_HOST'])) {
            $tracer .= '<br>' . $_SERVER['HTTP_HOST'];
            if (isset($_SERVER['PHP_SELF'])) {
                $tracer .= $_SERVER['PHP_SELF'];
            }
        } elseif (isset($_SERVER['PHP_SELF'])) {
            $tracer .= '<br>' . $_SERVER['PHP_SELF'];
        }
        $tracer = (string) substr($tracer, 0, 500);
        if (is_array($inputarr)) {
            if (is_array(reset($inputarr))) {
                $params = 'Array sizeof=' . sizeof($inputarr);
            } else {
                // Quote string parameters so we can see them in the
                // performance stats. This helps spot disabled indexes.
                $xar_params = $inputarr;
                foreach ($xar_params as $xar_param_key => $xar_param) {
                    if (gettype($xar_param) == 'string') {
                        $xar_params[$xar_param_key] = '"' . $xar_param . '"';
                    }
                }
                $params = implode(', ', $xar_params);
                if (strlen($params) >= 3000) {
                    $params = substr($params, 0, 3000);
                }
            }
        } else {
            $params = '';
        }
        if (is_array($sql)) {
            $sql = $sql[0];
        }
        $arr = array('b' => strlen($sql) . '.' . crc32($sql), 'c' => substr($sql, 0, 3900), 'd' => $params, 'e' => $tracer, 'f' => adodb_round($time, 6));
        $saved = $conn->debug;
        $conn->debug = 0;
        $d = $conn->sysTimeStamp;
        if (empty($d)) {
            $d = date("'Y-m-d H:i:s'");
        }
        /*
        // OCI/Informix/ODBC_MSSQL - not sure if/how available in adodb-lite so I've commented out the section for now - (Pádraic)
        */
        /*if ($dbT == 'oci8' && $dbT != 'oci8po')
        		{
        			$isql = "insert into $perf_table values($d,:b,:c,:d,:e,:f)";
        		}
        		elseif($dbT == 'odbc_mssql' || $dbT == 'informix')
        		{
        			$timer = $arr['f'];
        			if ($dbT == 'informix') $sql2 = substr($sql2,0,230);
        
        			$sql1 = $conn->qstr($arr['b']);
        			$sql2 = $conn->qstr($arr['c']);
        			$params = $conn->qstr($arr['d']);
        			$tracer = $conn->qstr($arr['e']);
        			
        			$isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values($d,$sql1,$sql2,$params,$tracer,$timer)";
        			if ($dbT == 'informix') $isql = str_replace(chr(10),' ',$isql);
        			$arr = false;
        		} else {*/
        $isql = "insert into {$perf_table} (created,sql0,sql1,params,tracer,timer) values( {$d},?,?,?,?,?)";
        //}
        $ok = $conn->Execute($isql, $arr);
        $conn->debug = $saved;
        if ($ok) {
            $conn->_logsql = true;
        } else {
            $err2 = $conn->ErrorMsg();
            $conn->_logsql = true;
            // enable logsql error simulation
            $perf =& NewPerfMonitor($conn);
            if ($perf) {
                if ($perf->CreateLogTable()) {
                    $ok = $conn->Execute($isql, $arr);
                }
            } else {
                $ok = $conn->Execute("create table {$perf_table} (\n\t\t\t\tcreated varchar(50),\n\t\t\t\tsql0 varchar(250), \n\t\t\t\tsql1 varchar(4000),\n\t\t\t\tparams varchar(3000),\n\t\t\t\ttracer varchar(500),\n\t\t\t\ttimer decimal(16,6))");
            }
            /*if (!$ok) {
            			ADOConnection::outp( "<p><b>LOGSQL Insert Failed</b>: $isql<br>$err2</p>");
            			$conn->_logsql = false;
            		}*/
        }
        $conn->_errorMsg = $errM;
        $conn->_errorCode = $errN;
    }
    return $rs;
}
Example #6
0
/**
 * Initializes the database connection.
 *
 * This function loads up ADODB  and starts the database
 * connection using the required parameters then it sets
 * the table prefixes and xartables up and returns true
 *
 * @access protected
 * @global object db database connection object
 * @global integer ADODB_FETCH_MODE array fectching by associative or numeric keyed arrays
 * @global array oosDB_tables database tables used by OOS [OSIS Online Shop]
 * @return bool true on success, false on failure
 */
function oosDBInit()
{
    // Get database parameters
    $dbtype = OOS_DB_TYPE;
    $dbhost = OOS_DB_SERVER;
    $dbname = OOS_DB_DATABASE;
    // Decode encoded DB parameters
    if (OOS_ENCODED == '1') {
        $dbuname = base64_decode(OOS_DB_USERNAME);
        $dbpass = base64_decode(OOS_DB_PASSWORD);
    } else {
        $dbuname = OOS_DB_USERNAME;
        $dbpass = OOS_DB_PASSWORD;
    }
    // Start connection
    global $ADODB_CACHE_DIR;
    $ADODB_CACHE_DIR = oos_get_local_path(OOS_TEMP_PATH . 'adodb_cache/');
    $dbconn = ADONewConnection($dbtype);
    if (!$dbconn->Connect($dbhost, $dbuname, $dbpass, $dbname)) {
        $dbpass = "******";
        $dbuname = "****";
        die("{$dbtype}://{$dbuname}:{$dbpass}@{$dbhost}/{$dbname} failed to connect " . $dbconn->ErrorMsg());
    }
    if (function_exists('memcache_pconnect')) {
        $dbconn->memCache = true;
        // should we use memCache instead of caching in files
        $dbconn->memCacheHost = '126.0.1.1';
        // $db->memCacheHost = array($ip1, $ip2, $ip3); // $db->memCacheHost = $ip1; still works
        $dbconn->memCachePort = '11211';
        // this is default memCache port
        $dbconn->memCacheCompress = false;
        // Use '1' to store the item compressed (uses zlib)
    }
    global $ADODB_FETCH_MODE;
    $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
    //$dbconn->debug = true;
    if (OOS_LOG_SQL == '1') {
        include 'includes/lib/adodb/adodb-perf.inc.php';
        adodb_perf::table(ADODB_LOGSQL_TABLE);
        $dbconn->LogSQL();
    }
    $GLOBALS['oosDB_connections'][0] =& $dbconn;
    $GLOBALS['oosDB_tables'] = array();
    return true;
}
ini_set('url_rewriter.tags', '');
// Ensure that the session id is *not* passed on the url - this is a possible security hole for logins - including admin.
global $ADODB_CRYPT_KEY;
global $ADODB_SESSION_CONNECT, $ADODB_SESSION_USER, $ADODB_SESSION_DB;
$ADODB_SESS_CONN = '';
$ADODB_SESSION_TBL = $db_prefix . "sessions";
// We explicitly use encrypted sessions, but this adds compression as well.
ADODB_Session::encryptionKey($ADODB_CRYPT_KEY);
// The data field name "data" violates SQL reserved words - switch it to SESSDATA
ADODB_Session::dataFieldName('SESSDATA');
global $db;
connectdb();
$db->prefix = $db_prefix;
$db->logging = $db_logging;
if ($db_logging) {
    adodb_perf::table("{$db->prefix}adodb_logsql");
    $db->LogSQL();
    // Turn on adodb performance logging
}
if (!isset($index_page)) {
    $index_page = false;
}
if (!$index_page) {
    // Ensure that we do not set cookies on the index page, until the player chooses to allow them.
    if (!isset($_SESSION)) {
        session_start();
    }
}
// reg_global_fix,0.1.1,22-09-2004,BNT DevTeam
if (!defined('reg_global_fix')) {
    define('reg_global_fix', True, TRUE);
Example #8
0
	function UI($pollsecs=5)
	{
	global $HTTP_GET_VARS,$HTTP_SERVER_VARS,$HTTP_POST_VARS;
	
    $perf_table = adodb_perf::table();
	$conn = $this->conn;
	
	$app = $conn->host;
	if ($conn->host && $conn->database) $app .= ', db=';
	$app .= $conn->database;
	
	if ($app) $app .= ', ';
	$savelog = $this->conn->LogSQL(false);	
	$info = $conn->ServerInfo();
	if (isset($HTTP_GET_VARS['clearsql'])) {
		$this->conn->Execute("delete from $perf_table");
	}
	$this->conn->LogSQL($savelog);
	
	// magic quotes
	
	if (isset($HTTP_GET_VARS['sql']) && get_magic_quotes_gpc()) {
		$_GET['sql'] = $HTTP_GET_VARS['sql'] = str_replace(array("\\'",'\"'),array("'",'"'),$HTTP_GET_VARS['sql']);
	}
	
	if (!isset($_SESSION['ADODB_PERF_SQL'])) $nsql = $_SESSION['ADODB_PERF_SQL'] = 10;
	else  $nsql = $_SESSION['ADODB_PERF_SQL'];
	
	$app .= $info['description'];
	
	
	if (isset($HTTP_GET_VARS['do'])) $do = $HTTP_GET_VARS['do'];
	else if (isset($HTTP_POST_VARS['do'])) $do = $HTTP_POST_VARS['do'];
	 else if (isset($HTTP_GET_VARS['sql'])) $do = 'viewsql';
	 else $do = 'stats';
	 
	if (isset($HTTP_GET_VARS['nsql'])) {
		if ($HTTP_GET_VARS['nsql'] > 0) $nsql = $_SESSION['ADODB_PERF_SQL'] = (integer) $HTTP_GET_VARS['nsql'];
	}
	echo "<title>ADOdb Performance Monitor on $app</title><body bgcolor=white>";
	if ($do == 'viewsql') $form = "<td><form># SQL:<input type=hidden value=viewsql name=do> <input type=text size=4 name=nsql value=$nsql><input type=submit value=Go></td></form>";
	else $form = "<td>&nbsp;</td>";
	
	$allowsql = !defined('ADODB_PERF_NO_RUN_SQL');
	
	if  (empty($HTTP_GET_VARS['hidem']))
	echo "<table border=1 width=100% bgcolor=lightyellow><tr><td colspan=2>
	<b><a href=http://php.weblogs.com/adodb?perf=1>ADOdb</a> Performance Monitor</b> <font size=1>for $app</font></tr><tr><td>
	<a href=?do=stats><b>Performance Stats</b></a> &nbsp; <a href=?do=viewsql><b>View SQL</b></a>
	 &nbsp; <a href=?do=tables><b>View Tables</b></a> &nbsp; <a href=?do=poll><b>Poll Stats</b></a>",
	 $allowsql ? ' &nbsp; <a href=?do=dosql><b>Run SQL</b></a>' : '',
	 "$form",
	 "</tr></table>";

	 
	 	switch ($do) {
		default:
		case 'stats':
			echo $this->HealthCheck();
			//$this->conn->debug=1;
			echo $this->CheckMemory();
			break;
		case 'poll':
			echo "<iframe width=720 height=80% 
				src=\"{$HTTP_SERVER_VARS['PHP_SELF']}?do=poll2&hidem=1\"></iframe>";
			break;
		case 'poll2':
			echo "<pre>";
			$this->Poll($pollsecs);
			break;
		
		case 'dosql':
			if (!$allowsql) break;
			
			$this->DoSQLForm();
			break;
		case 'viewsql':
			if (empty($HTTP_GET_VARS['hidem']))
				echo "&nbsp; <a href=\"?do=viewsql&clearsql=1\">Clear SQL Log</a><br>";
			echo($this->SuspiciousSQL($nsql));
			echo($this->ExpensiveSQL($nsql));
			echo($this->InvalidSQL($nsql));
			break;
		case 'tables': 
			echo $this->Tables(); break;
		}
		global $ADODB_vers;
		echo "<p><div align=center><font size=1>$ADODB_vers Sponsored by <a href=http://phplens.com/>phpLens</a></font></div>";
	}
 function ExpensiveSQL($numsql = 10)
 {
     return adodb_perf::_ExpensiveSQL($numsql);
 }