Location: PHPKode > scripts > phpDebugger > debuginc.php
<?php
// * 
// * DebugInc.php - Include this in each module
// * where you will call the OutputDebugString()
// * function. It assumes you already have a 
// * valid working connection to your database.
// * If you want this to work independently then
// * you will need to include your own sql code
// * and call it prior to saving this to mysql.
// * 
// * Project was written by Phil Petree
// * and is available at philpetree.com
// * and is released under GNU license.
// * Copyright (C) 2010 by Phill Petree. All rights reserved worldwide.
// * US Governement users have restricted rights.
// *  
// * Ver 1.0 - Release date: June 22, 2010
// * 


// if necessary, pull in our sql libs & connection data
// include "../include/sql_config.php";

// on many production servers debug_backtrace is not available
// so if its included in a script, the script will hang.
// to avoid the hang, set the following variable to 0 AND
// comment out the call to debug_backtrace in the function 
// getFunctionName().  NOTE: function_exist() may also not
// be defined so this creates a situation where you are double
// trapped. At time of release is_callable() was functioning
// and all errors/bugs were avoided... I'm just sayin...
$detect_function = 1;


function OutputDebugString($string)
{
  // allow ' / etc (hopefully programmers wont try sql injection hacks! ;-))
  $string = mysql_real_escape_string($string);
  
  // get the name of the script this is being called from
  $module = $_SERVER["SCRIPT_NAME"];
  
  // get the name of the subroutine this is called from
  if($detect_function > 0)
  {
    $f = getFunctionName();
    // prepend the function name to the output string
    if($f) $string = "$f(): $string";
  }
  // we're only inserting these 2 values because
  // the record id is auto_increment AND
  // the date_time is a default TIMESTAMP  
  $query = "INSERT INTO debug (module, string) VALUES('$module','$string')";
  $result = mysql_query($query) or die(mysql_error());
}

// returns the function this was called from
// one could use this to get the entire call tree
// this routine will cause a performace hit... 
// so dont leave it in production code!!! 
function getFunctionName()
{
  $backtrace = "debug_backtrace";
  if(is_callable($backtrace))
  {
    $backtrace = debug_backtrace();
    return $backtrace[2]['function'];
  }
  return "";
}
?>
Return current item: phpDebugger