function dumpError($sql) { if (Kennel::$ROOT_URL && !Request::isAjax()) { // Non-ajax HTTP Request $table = XML::element('table', null, array('border' => '1')); $tr = XML::element('tr', $table); $th = XML::element('th', $tr, array('colspan' => '2'), "SQL query returned an error"); $tr = XML::element('tr', $table); $th = XML::element('th', $tr, null, 'query'); $td = XML::element('td', $tr, null, syntax::mysql($sql)); $tr = XML::element('tr', $table); $th = XML::element('th', $tr, null, 'error'); $td = XML::element('td', $tr, null, mysql_error(self::$CONN)); $full_backtrace = debug_backtrace(); $backtrace = $full_backtrace[2]; if (isset($backtrace['file'])) { $tr = XML::element('tr', $table); $th = XML::element('th', $tr, null, 'file'); $td = XML::element('td', $tr, null, $backtrace['file']); } if (isset($backtrace['line'])) { $tr = XML::element('tr', $table); $th = XML::element('th', $tr, null, 'line'); $td = XML::element('td', $tr, null, $backtrace['line']); } if ($backtrace['class']) { $tr = XML::element('tr', $table); $th = XML::element('th', $tr, null, 'class'); $td = XML::element('td', $tr, null, $backtrace['class']); } if ($backtrace['function']) { $tr = XML::element('tr', $table); $th = XML::element('th', $tr, null, 'function'); $td = XML::element('td', $tr, null, $backtrace['function']); } echo $table; } else { // Ajax or cli $default = "[0m"; echo "\n[1;30;41m"; // red background, bold echo "SQL query returned an error:{$default}\n"; $lines = explode("\n", $sql); foreach ($lines as $line) { echo " {$line}\n"; } $error = mysql_error(self::$CONN); echo "[31m"; // red echo "{$error}{$default}\n\n"; } die; }
static function dump(Criteria $criteria) { if (!self::$DB) { self::$DB = new MySQL(); } $schema = self::getSchema($criteria->from_model_name); $relationships = $schema->getRelationships(); foreach ($relationships as $rel) { $criteria->addJoin($rel->foreignModel, "{$criteria->from_model_name}.{$rel->name}", "{$rel->foreignModel}.{$rel->foreignKey}", Criteria::LEFT_JOIN); } $sql = self::getSelectString($criteria); if (Kennel::$ROOT_URL) { echo syntax::mysql($sql); } else { echo $sql; } // Running from the cli return; }