RedBeanPHP\Facade::debug PHP Method

debug() public static method

In Debug mode all SQL that happens under the hood will be printed to the screen and/or logged. If no database connection has been configured using R::setup() or R::selectDatabase() this method will throw an exception. There are 2 debug styles: Classic: separate parameter bindings, explicit and complete but less readable Fancy: interpersed bindings, truncates large strings, highlighted schema changes Fancy style is more readable but sometimes incomplete. The first parameter turns debugging ON or OFF. The second parameter indicates the mode of operation: 0 Log and write to STDOUT classic style (default) 1 Log only, class style 2 Log and write to STDOUT fancy style 3 Log only, fancy style This function always returns the logger instance created to generate the debug messages.
public static debug ( boolean $tf = TRUE, integer $mode ) : RDefault
$tf boolean debug mode (TRUE or FALSE)
$mode integer mode of operation
return RedBeanPHP\Logger\RDefault
    public static function debug($tf = TRUE, $mode = 0)
    {
        if ($mode > 1) {
            $mode -= 2;
            $logger = new Debug();
        } else {
            $logger = new RDefault();
        }
        if (!isset(self::$adapter)) {
            throw new RedException('Use R::setup() first.');
        }
        $logger->setMode($mode);
        self::$adapter->getDatabase()->setDebugMode($tf, $logger);
        return $logger;
    }

Usage Example

Example #1
0
 /**
  * Test explicit flush.
  * 
  * @return void
  */
 public function testExplicitCacheFlush()
 {
     testpack('Test cache flush (explicit)');
     R::debug(true, 1);
     $logger = R::getDatabaseAdapter()->getDatabase()->getLogger();
     $bean = R::dispense('bean');
     $bean->title = 'abc';
     $id1 = R::store($bean);
     $logger->clear();
     $bean = R::load('bean', $id1);
     asrt($bean->title, 'abc');
     asrt(count($logger->grep('SELECT *')), 1);
     $bean = R::load('bean', $id1);
     asrt(count($logger->grep('SELECT *')), 1);
     R::getWriter()->flushCache();
     $bean = R::load('bean', $id1);
     asrt(count($logger->grep('SELECT *')), 2);
     R::getWriter()->flushCache();
     R::getWriter()->setUseCache(FALSE);
 }
All Usage Examples Of RedBeanPHP\Facade::debug