Source for file bit_error_inc.php
Documentation is available at bit_error_inc.php
* Custom ADODB Error Handler. This will be called with the following params
* @version V3.94 13 Oct 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
* Set tabs to 4 for best viewing.
* Latest version is available at http://php.weblogs.com
if( !defined( 'BIT_INSTALL' ) && !defined( 'ADODB_ERROR_HANDLER' ) ) {
define( 'ADODB_ERROR_HANDLER', 'bit_error_handler' );
function bit_log_error( $pLogMessage, $pSubject, $pFatal = TRUE ) {
// You can prevent sending of error emails by adding define('ERROR_EMAIL', ''); in your config_inc.php
$errorEmail = defined( 'ERROR_EMAIL' ) ? ERROR_EMAIL : (!empty( $_SERVER['SERVER_ADMIN'] ) ? $_SERVER['SERVER_ADMIN'] : NULL);
if( ( !defined( 'IS_LIVE' ) || !IS_LIVE ) ) {
print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<title>bitweaver - White Screen of Death</title>
<body style="background:#fff; font-family:monospace;">';
// print "<h1>Upgrade Beta 1 to Beta 2</h1>If you are getting this error because you just upgraded your bitweaver from Beta 1 to Beta 2, please follow this link to the installer, which will guide you through the upgrade process: <a href='".BIT_ROOT_URL."install/install.php?step=4'>Upgrade Beta 1 to Beta 2</a>";
print "<h1 style=\"color:#900; font-weight:bold;\">You are running bitweaver in TEST mode</h1>\n";
<li><a href='http://sourceforge.net/tracker/?func=add&group_id=141358&atid=749176'>Click here to log a bug</a>, if this appears to be an error with the application.</li>
<li><a href='". BIT_ROOT_URL. "install/install.php'>Go here to begin the installation process</a>, if you haven't done so already.</li>
<li>To hide this message, please <strong>set the IS_LIVE constant to TRUE</strong> in your kernel/config_inc.php file.</li>
print "<pre>". $pLogMessage. "</pre>";
} elseif( $errorEmail ) {
mail( $errorEmail, "$pSubject", $pLogMessage );
if( ( defined( 'AUTO_BUG_SUBMIT' ) && AUTO_BUG_SUBMIT ) ) {
mail( 'bugs@bitweaver.org',"$subject $pSubject",$pLogMessage );
$date = date("D M d H:i:s Y"); // [Tue Sep 24 12:19:20 2002] [error]
if( isset ( $gBitUser->mInfo ) ) {
$acctStr = "ID: ". $gBitUser->mInfo['user_id']. " - Login: ". $gBitUser->mInfo['login']. " - e-mail: ". $gBitUser->mInfo['email'];
$acctStr = "User unknown";
$info .= $indent. "-----------------------------------------------------------------------------------------------". $separator;
$info .= $indent. "#### USER AGENT: ". $_SERVER['HTTP_USER_AGENT']. $separator;
$info .= $indent. "#### ACCT: ". $acctStr. $separator;
$info .= $indent. "#### URL: http://". $_SERVER['HTTP_HOST']. $_SERVER['REQUEST_URI']. $separator;
if( isset ($_SERVER['HTTP_REFERER'] ) ) {
$info .= $indent. "#### REFERRER: $_SERVER[HTTP_REFERER]". $separator;
$info .= $indent. "#### HOST: $_SERVER[HTTP_HOST]". $separator;
$info .= $indent. "#### IP: $_SERVER[REMOTE_ADDR]". $separator;
if( $gBitDb && isset ( $php_errormsg ) ) {
$info .= $indent. "#### PHP: ". $php_errormsg. $separator;
if ( $iDBParms['sql'] ) {
$badSpace = array("\n", "\t");
$info .= $indent. "#### SQL: ". str_replace($badSpace, ' ', $iDBParms['sql']). $separator;
$info .= $indent. '['. implode( ', ', $iDBParms['p2'] ). ']'. $separator;
$errno = ((int) $iDBParms['errno'] ? 'Errno: '. $iDBParms['errno'] : '');
$info .= $indent. "#### ERROR CODE: ". $errno. " Message: ". $iDBParms['db_msg'];
$stackTrace = bt( 9999, FALSE );
//multiline expressions matched
if ( preg_match_all("/.*adodb_error_handler\([^\}]*\)(.+\}.+)/ms", $stackTrace, $match) ) {
$stackTrace = $match[1][0];
$ret = $info. $separator. $separator. $stackTrace;
if (!function_exists('bt')) { // Make sure another backtrace function does not exist
function bt( $levels= 9999, $iPrint= TRUE ) {
if (PHPVERSION() >= 4.3) {
foreach ($traceArr as $arr) {
for ($i= 0; $i <= $tabs; $i++ ) {
if ( isset ($arr['class']) ) {
$sClass .= $arr['class']. '::';
if ( isset ($arr['args']) ) {
foreach( $arr['args'] as $v ) {
} elseif (is_bool($v)) { $args[] = $v ? 'true' : 'false';
if (strlen($v) > $MAXSTRLEN) $str .= '...';
$s .= "\n ". $indent. ' -> ';
$s .= $sClass. $arr['function']. '('. implode(', ',$args). ')';
$s .= @sprintf(" LINE: %4d, %s", $arr['line'],$arr['file']);
print '<pre>'. $s. "</pre>\n";
} // End if function_exists('bt')
// var dump variable in something nicely readable in web browser
// var capture variable in something nicely readable in web browser
function vc( $iVar, $pHtml= TRUE ) {
if( isset ( $iVar->mDb ) ) {
} elseif( $pHtml && !empty( $_SERVER['HTTP_USER_AGENT'] ) && $_SERVER['HTTP_USER_AGENT'] != 'cron' && ((is_object( $iVar ) && !empty( $iVar )) || is_array( $iVar )) ) {
} elseif( is_string( $iVar ) && !empty( $_SERVER['HTTP_USER_AGENT'] ) && $_SERVER['HTTP_USER_AGENT'] != 'cron' ) {
echo "<div><span style='background-color:black;color:white;padding:.5ex;font-weight:bold;'>Var Anatomy</div>";
echo "<div style='border:1px solid black;padding:2ex;background-color:#efe6d6;'>$dbg</div>";
|