function _collection_find($field, $value, $op = '=', $sort = null, $limit = null, $start = 0, $direction = 'DESC') { Plank_Logger::log('MDL' . $this->_dbTable, "Finding items with a {$field} {$op} {$value}", L_DEBUG); $sql = sprintf('select * from %s where %s %s :value', $this->_dbTable, $field, $op); if (!is_null($sort)) { $sql .= sprintf(' order by %s %s', $sort, $direction); } if (!is_null($limit)) { sprintf(' limit %d, %d', $start, $limit); } // Initialise database connection $db = Plank_DB::getInstance(); $cxn = $db->connection('slave'); $query = $cxn->prepare($sql, MDB2_PREPARE_MANIP); $db->checkError($query); $result = $query->execute(array('value' => $value)); $db->checkError($result); return $result->fetchAll(); }
function display() { if (!defined('SHOWDEBUG') || !SHOWDEBUG) { return; } $out = <<<EOW \t\t \t<!-- begin Plank Inline Debuggery --> \t<script type="text/javascript"> \t \t\tfunction plankShowDebug(what){ \t\t\tdocument.getElementById('plankDebugLogs').style.display = 'none'; \t\t\tdocument.getElementById('plankDebugQueries').style.display = 'none'; \t\t\tdocument.getElementById('plankDebugStats').style.display = 'none'; \t\t\t \t\t\tdocument.getElementById(what).style.display = 'block'; \t\t\t \t\t} \t\t \t\tfunction plankHideDebug(){ \t\t\tdocument.getElementById('plankDebugPane').style.display = 'none'; \t\t} \t \t</script> \t<style type="text/css"> \t\t#plankDebugPane { \t\t\topacity: .25; \t\t\tfilter: alpha(opacity=25); \t\t\t-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=25)"; \t\t\tborder: 1px solid red;\t \t\t\tposition: absolute; \t\t\ttop: 0; \t\t\tright: 0; \t\t\tz-index: 10000; \t\t\tbackground: #FFF; \t\t\tfont-family: "Trebuchet MS" sans-serif; \t\t\tborder: 1px solid #840000;\t \t\t\t-moz-border-radius: 15px 0 15px 30px; \t\t\t-webkit-border-radius: 30px 60px 30px 60px; \t\t\t \t\t\t \t\t\tpadding-left: .5em; \t\t} \t\t \t\t#plankDebugPane:hover { \t\t\topacity: .85; \t\t\tfilter: alpha(opacity=85); \t\t\t-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=85)"; \t\t} \t \t\t#plankDebugPane div.logView { \t\t\tpadding-bottom: 1em; \t\t\toverflow: auto; \t\t\tmax-width: 100%; \t\t\twidth: 1024px; \t\t} \t\t \t\t.plankLogo { \t\t\tcolor: #840000; \t\t\tfont-size: larger;\t \t\t} \t</style> \t EOW; $logOutput = Plank_Logger_Output::getInstance(); list($log, $queries, $stats) = $logOutput->giveMeLogs(); echo ' <div id="plankDebugPane"> <div class="plankDebugNav"><span class="plankLogo">Plank</span>: Show [ <a href="javascript:plankShowDebug(\'plankDebugLogs\')">' . count($log) . ' Logs</a> | <a href="javascript:plankShowDebug(\'plankDebugQueries\')">Queries</a> | <a href="javascript:plankShowDebug(\'plankDebugStats\')">' . count($stats) . ' Timings</a> | <a href="javascript:plankShowDebug(\'plankDebugPane\')">Nothing</a> | <a href="javascript:plankHideDebug()">X</a>]</div> '; $strf = "<tt>[%2.5f][%d][%s]</tt> %s<br />"; $out .= '<div id="plankDebugLogs" class="logView" style="display: none"><h2>Logs</h2>'; foreach ($log as $logline) { if (is_array($logline[2])) { foreach ($logline[2] as $index => $item) { $out .= sprintf($strf, $logline[0] - T, $logline[3], $logline[1], "<tt>[{$index}]</tt>" . $item); } } else { $out .= sprintf($strf, $logline[0] - T, $logline[3], $logline[1], htmlentities($logline[2])); } } $out .= "\n</div>"; $out .= '<div id="plankDebugQueries" class="logView" style="display: none"><h2>Queries</h2>'; if (Plank_DB::hasInstance()) { $db = Plank_DB::getInstance(); foreach ($db->listConnections() as $connection) { $out .= $db->connection($connection)->getDebugOutput(); } } else { $out .= 'No Queries'; } $out .= "\n</div>"; $out .= '<div id="plankDebugStats" class="logView" style="display: none"><h2>Stats</h2>'; foreach ($stats as $logline) { $message = $logline[2]; if (is_array($message)) { foreach ($message as $index => $item) { $out .= sprintf('[%2.5f][%s] %s<br/>', $logline[0] - T, $logline[1], $index . " - " . $item); } } else { $out .= sprintf('[%2.5f][%s] %s<br/>', $logline[0] - T, $logline[1], $logline[2]); } } $out .= sprintf('( %2.5f total)', microtime(true) - T); $out .= "\n</div>"; $out .= ' </div>'; return $out; }
static function connection($connection) { $db = Plank_DB::getInstance(); return $db->_getConnection($connection); }