orgtable - create links from these columns $indexes = array(); // orgtable => array(column => colno) - primary keys $columns = array(); // orgtable => array(column => ) - not selected columns in primary key $blobs = array(); // colno => bool - display bytes for blobs $types = array(); // colno => type - display char in $return = array(); // table => orgtable - mapping to use in EXPLAIN odd(''); // reset odd for each result for ($i=0; (!$limit || $i < $limit) && ($row = $result->fetch_row()); $i++) { if (!$i) { echo "\n"; echo ""; for ($j=0; $j < count($row); $j++) { $field = $result->fetch_field(); $name = $field->name; $orgtable = $field->orgtable; $orgname = $field->orgname; $return[$field->table] = $orgtable; if ($orgtables && $jush == "sql") { // MySQL EXPLAIN $links[$j] = ($name == "table" ? "table=" : ($name == "possible_keys" ? "indexes=" : null)); } elseif ($orgtable != "") { if (!isset($indexes[$orgtable])) { // find primary key in each table $indexes[$orgtable] = array(); foreach (indexes($orgtable, $connection2) as $index) { if ($index["type"] == "PRIMARY") { $indexes[$orgtable] = array_flip($index["columns"]); break; } } $columns[$orgtable] = $indexes[$orgtable]; } if (isset($columns[$orgtable][$orgname])) { unset($columns[$orgtable][$orgname]); $indexes[$orgtable][$orgname] = $j; $links[$j] = $orgtable; } } if ($field->charsetnr == 63) { // 63 - binary $blobs[$j] = true; } $types[$j] = $field->type; echo "name != $orgname ? " title='" . h(($orgtable != "" ? "$orgtable." : "") . $orgname) . "'" : "") . ">" . h($name) . ($orgtables ? doc_link(array('sql' => "explain-output.html#explain_" . strtolower($name))) : "") ; } echo "\n"; } echo ""; foreach ($row as $key => $val) { if ($val === null) { $val = "NULL"; } elseif ($blobs[$key] && !is_utf8($val)) { $val = "" . lang('%d byte(s)', strlen($val)) . ""; //! link to download } elseif (!strlen($val)) { // strlen - SQLite can return int $val = " "; // some content to print a border } else { $val = h($val); if ($types[$key] == 254) { // 254 - char $val = "$val"; } } if (isset($links[$key]) && !$columns[$links[$key]]) { if ($orgtables && $jush == "sql") { // MySQL EXPLAIN $table = $row[array_search("table=", $links)]; $link = $links[$key] . urlencode($orgtables[$table] != "" ? $orgtables[$table] : $table); } else { $link = "edit=" . urlencode($links[$key]); foreach ($indexes[$links[$key]] as $col => $j) { $link .= "&where" . urlencode("[" . bracket_escape($col) . "]") . "=" . urlencode($row[$j]); } } $val = "$val"; } echo "
$val"; } } echo ($i ? "
" : "

" . lang('No rows.')) . "\n"; return $return; } /** Get referencable tables with single column primary key except self * @param string * @return array ($table_name => $field) */ function referencable_primary($self) { $return = array(); // table_name => field foreach (table_status('', true) as $table_name => $table) { if ($table_name != $self && fk_support($table)) { foreach (fields($table_name) as $field) { if ($field["primary"]) { if ($return[$table_name]) { // multi column primary key unset($return[$table_name]); break; } $return[$table_name] = $field; } } } } return $return; } /** Print SQL "; } /** Print table columns for type edit * @param string * @param array * @param array * @param array returned by referencable_primary() * @param array extra types to prepend * @return null */ function edit_type($key, $field, $collations, $foreign_keys = array(), $extra_types = array()) { global $structured_types, $types, $unsigned, $on_actions; $type = $field["type"]; ?> " size="3" aria-labelledby="label-length">