Skip to content

Instantly share code, notes, and snippets.

@GDmac
Last active December 29, 2015 15:19

Revisions

  1. GDmac revised this gist Dec 31, 2013. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions database_DB_driver.php
    Original file line number Diff line number Diff line change
    @@ -18,18 +18,18 @@ function get_caller_info() {
    $func = '';
    $class = '';
    $trace = debug_backtrace();
    if (isset($trace[2])) {
    $file = $trace[1]['file'];
    $line = $trace[1]['line'];
    $func = $trace[2]['function'];
    if ((substr($func, 0, 7) == 'include') || (substr($func, 0, 7) == 'require')) {
    $func = '';
    }
    } else if (isset($trace[1])) {
    $file = $trace[1]['file'];
    $line = $trace[1]['line'];
    $func = '';
    }
    // if (isset($trace[2])) {
    // $file = $trace[1]['file'];
    // $line = $trace[1]['line'];
    // $func = $trace[2]['function'];
    // if ((substr($func, 0, 7) == 'include') || (substr($func, 0, 7) == 'require')) {
    // $func = '';
    // }
    // } else if (isset($trace[1])) {
    // $file = $trace[1]['file'];
    // $line = $trace[1]['line'];
    // $func = '';
    // }
    if (isset($trace[3]['class'])) {
    $class = $trace[3]['class'];
    $func = $trace[3]['function'];
  2. GDmac revised this gist Nov 30, 2013. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions database_DB_driver.php
    Original file line number Diff line number Diff line change
    @@ -10,9 +10,7 @@
    $this->queries[] = $sql . "\n# ".get_caller_info();
    }

    // ...
    // add get_caller_info funtion somewhere in global scope

    // get_caller_info funtion somewhere in global scope
    function get_caller_info() {
    $c = '';
    $file = '';
  3. GDmac revised this gist Nov 30, 2013. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions database_DB_driver.php
    Original file line number Diff line number Diff line change
    @@ -4,15 +4,14 @@

    // database/DB_driver.php method query()
    //...

    // Save the query for debugging
    if ($this->save_queries == TRUE)
    {
    $this->queries[] = $sql . "\n# ".get_caller_info();
    }

    // ...
    // add this funtion somewhere
    // add get_caller_info funtion somewhere in global scope

    function get_caller_info() {
    $c = '';
  4. GDmac revised this gist Nov 30, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions database_DB_driver.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    // from http://php.net/manual/en/function.debug-backtrace.php#111255
    // adapted for codeigniter

  5. GDmac revised this gist Nov 30, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions database_DB_driver.php
    Original file line number Diff line number Diff line change
    @@ -45,9 +45,9 @@ function get_caller_info() {
    }
    if ($file != ''){
    if (strpos($file,BASEPATH)===0) {
    $file = 'CI ' . basename($file);
    $file = 'CI ' . str_replace(BASEPATH,'',$file);
    }elseif (strpos($file,APPPATH)===0) {
    $file = 'APP ' . basename($file);
    $file = 'APP ' . str_replace(APPPATH,'',$file);
    }else {
    $file = 'UNKNOWN ' . basename($file);
    }
  6. GDmac revised this gist Nov 30, 2013. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions database_DB_driver.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,18 @@
    // from http://php.net/manual/en/function.debug-backtrace.php#111255
    // adapted for codeigniter

    // database/DB_driver.php method query()
    //...

    // Save the query for debugging
    if ($this->save_queries == TRUE)
    {
    $this->queries[] = $sql . "\n# ".get_caller_info();
    }

    // ...
    // add this funtion somewhere

    function get_caller_info() {
    $c = '';
    $file = '';
  7. GDmac revised this gist Nov 30, 2013. 1 changed file with 45 additions and 30 deletions.
    75 changes: 45 additions & 30 deletions database_DB_driver.php
    Original file line number Diff line number Diff line change
    @@ -1,30 +1,45 @@
    // ...

    // Save the query for debugging
    if ($this->save_queries == TRUE)
    {

    // ADDED: Some backtracing
    $file = '';
    $callstack = debug_backtrace();
    if(count($callstack) >= 2)
    {
    //list($callee) = $callstack[1];
    if (strpos($callstack[1]['file'], BASEPATH)===0)
    {
    $file = 'CI/'.str_replace(BASEPATH, '', $callstack[1]['file']);
    }
    elseif (strpos($callstack[1]['file'], APPPATH)===0)
    {
    $file = 'APP/'.str_replace(APPPATH, '', $callstack[1]['file']);
    }
    else
    {
    $file = 'UNKNOWN : '.$callstack[1]['file'];
    }
    $file = "\n#".$file.' L:'.$callstack[1]['line'];
    }

    $this->queries[] = $sql . $file;

    }
    function get_caller_info() {
    $c = '';
    $file = '';
    $line = '';
    $func = '';
    $class = '';
    $trace = debug_backtrace();
    if (isset($trace[2])) {
    $file = $trace[1]['file'];
    $line = $trace[1]['line'];
    $func = $trace[2]['function'];
    if ((substr($func, 0, 7) == 'include') || (substr($func, 0, 7) == 'require')) {
    $func = '';
    }
    } else if (isset($trace[1])) {
    $file = $trace[1]['file'];
    $line = $trace[1]['line'];
    $func = '';
    }
    if (isset($trace[3]['class'])) {
    $class = $trace[3]['class'];
    $func = $trace[3]['function'];
    $file = $trace[2]['file'];
    $line = $trace[2]['line'];
    } else if (isset($trace[2]['class'])) {
    $class = $trace[2]['class'];
    $func = $trace[2]['function'];
    $file = $trace[1]['file'];
    $line = $trace[1]['line'];
    }
    if ($file != ''){
    if (strpos($file,BASEPATH)===0) {
    $file = 'CI ' . basename($file);
    }elseif (strpos($file,APPPATH)===0) {
    $file = 'APP ' . basename($file);
    }else {
    $file = 'UNKNOWN ' . basename($file);
    }
    }
    $c = $file . ": ";
    $c .= ($class != '') ? ":" . $class . "->" : "";
    $c .= ($func != '') ? $func . "(): " : "";
    $c .= ' Line: '.$line;
    return($c);
    }
  8. GDmac revised this gist Nov 28, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion database_DB_driver.php
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@
    {
    $file = 'UNKNOWN : '.$callstack[1]['file'];
    }
    $file = "\n#" . $file;
    $file = "\n#".$file.' L:'.$callstack[1]['line'];
    }

    $this->queries[] = $sql . $file;
  9. GDmac revised this gist Nov 28, 2013. 1 changed file with 17 additions and 17 deletions.
    34 changes: 17 additions & 17 deletions database_DB_driver.php
    Original file line number Diff line number Diff line change
    @@ -1,29 +1,29 @@
    //...
    // ...

    // Save the query for debugging
    if ($this->save_queries == TRUE)
    {

    // Some backtracing
    // ADDED: Some backtracing
    $file = '';
    $callstack = debug_backtrace();
    if(count($callstack) >= 2)
    {
    //list($callee) = $callstack[1];
    if (strpos($callstack[1]['file'], BASEPATH)===0)
    {
    $file = 'CI/'.str_replace(BASEPATH, '', $callstack[1]['file']);
    }
    elseif (strpos($callstack[1]['file'], APPPATH)===0)
    {
    $callstack = debug_backtrace();
    if(count($callstack) >= 2)
    {
    //list($callee) = $callstack[1];
    if (strpos($callstack[1]['file'], BASEPATH)===0)
    {
    $file = 'CI/'.str_replace(BASEPATH, '', $callstack[1]['file']);
    }
    elseif (strpos($callstack[1]['file'], APPPATH)===0)
    {
    $file = 'APP/'.str_replace(APPPATH, '', $callstack[1]['file']);
    }
    else
    {
    }
    else
    {
    $file = 'UNKNOWN : '.$callstack[1]['file'];
    }
    $file = "\n #" . $file;
    }
    $file = "\n#" . $file;
    }

    $this->queries[] = $sql . $file;

  10. GDmac created this gist Nov 28, 2013.
    30 changes: 30 additions & 0 deletions database_DB_driver.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    //...

    // Save the query for debugging
    if ($this->save_queries == TRUE)
    {

    // Some backtracing
    $file = '';
    $callstack = debug_backtrace();
    if(count($callstack) >= 2)
    {
    //list($callee) = $callstack[1];
    if (strpos($callstack[1]['file'], BASEPATH)===0)
    {
    $file = 'CI/'.str_replace(BASEPATH, '', $callstack[1]['file']);
    }
    elseif (strpos($callstack[1]['file'], APPPATH)===0)
    {
    $file = 'APP/'.str_replace(APPPATH, '', $callstack[1]['file']);
    }
    else
    {
    $file = 'UNKNOWN : '.$callstack[1]['file'];
    }
    $file = "\n #" . $file;
    }

    $this->queries[] = $sql . $file;

    }