Only works if the 'logging' config option is
set to true. Otherwise, returned array will be empty.
public static get_query_log ( string $connection_name = self::DEFAULT_CONNECTION ) | ||
$connection_name | string | Which connection to use |
function call() { $app = $this->app; $res = $app->response(); try { $this->next->call(); if (self::$disabled) { return; } if ($res->status() !== 200) { return; } $res['Content-Type'] = 'application/json'; $result = self::prepForEncoding(self::$result); $res->status(200); } catch (Exception $e) { if ($e instanceof PDOException) { $log = $app->getLog(); foreach (ORM::get_query_log() as $entry) { $log->debug($entry); } } $res['Content-Type'] = 'application/json'; $result = array('error' => $e->getMessage()); $log = $app->getLog(); $log->debug($e->getMessage() . "\n" . $e->getTraceAsString()); if ($e instanceof AccessException) { $res->status($e->getCode()); } else { $res->status(500); } } // encode $res->write(defined('JSON_PRETTY_PRINT') ? json_encode($result, JSON_PRETTY_PRINT & JSON_NUMERIC_CHECK) : json_encode($result, JSON_NUMERIC_CHECK)); }
public static function getDebugInfo() { $enabled = self::$enabled && session_getUserNick() == pref_getDebugUser(); smarty_assign('debug_enabled', $enabled); if ($enabled) { smarty_assign('debug_messages', self::$debugInfo); smarty_assign('debug_runningTimeMillis', self::getRunningTimeInMillis()); smarty_assign('debug_ormQueryLog', ORM::get_query_log()); } }
public static function show($file) { // View paramater is deprecated and should not be used $view = Base::$g + self::$tpl; $view['content'] = self::$mst->render($file, $view); echo self::$mst->render('wrapper', $view); if (DEBUG) { $debug = array_count_values(ORM::get_query_log()); $debug = print_r($debug, 1); $debug = str_replace("\n", '<br>', $debug); echo $debug; } exit; }
public function testChainedRelationships() { $owner = Owner::with(array('car' => array('with' => 'manufactor')))->find_one(1); $fullQueryLog = ORM::get_query_log(); // Return last three queries $actualSql = array_slice($fullQueryLog, count($fullQueryLog) - 3); $expectedSql = array(); $expectedSql[] = "SELECT * FROM `owner` WHERE `id` = '1' LIMIT 1"; $expectedSql[] = "SELECT * FROM `car` WHERE `owner_id` IN ('1')"; $expectedSql[] = "SELECT * FROM `manufactor` WHERE `id` IN ('1')"; $this->assertEquals($expectedSql, $actualSql); }
$namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName .= str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, strtolower($className)) . '.php'; // error_log($fileName); if (file_exists($fileName)) { return require $fileName; } }); // Initialize Slim: $app = new \Slim\Slim(array('templates.path' => ROOT . '/templates', 'log.enabled' => true)); // Load config management library: require ROOT . '/common/config.php'; // Set logging level: $log = $app->getLog(); $log->setLevel(config('log.level', 0)); // Load default libraries: require ROOT . '/common/memcached.php'; require ROOT . '/common/db.php'; require ROOT . '/common/session.php'; // Setup the slim.after hook for printing DB log $app->hook('slim.after', function () use($app) { foreach (ORM::get_query_log() as $entry) { $app->getLog()->debug($entry); } }); // Add API functionality if (config('use.api', false)) { require ROOT . '/common/api.php'; }
public function get_query_log() { return \ORM::get_query_log($this->connectionName); }
public function getQueryLog() { return \ORM::get_query_log(); }
public static function getDebugInfo() { $enabled = self::$enabled && session_getUserNick() == Config::get('global.debugUser'); return array('enabled' => $enabled, 'messages' => self::$debugInfo, 'runningTimeMillis' => self::getRunningTimeInMillis(), 'ormQueryLog' => ORM::get_query_log()); }