/** * Returns recently used tables from phpMyAdmin database. * * @return array */ public function getFromDb() { // Read from phpMyAdmin database, if recent tables is not in session $sql_query = " SELECT `tables` FROM " . $this->pma_table . " WHERE `username` = '" . $GLOBALS['cfg']['Server']['user'] . "'"; $row = PMA_DBI_fetch_array(PMA_query_as_controluser($sql_query)); if (isset($row[0])) { return json_decode($row[0], true); } else { return array(); } }
/** * Returns recently used tables from phpMyAdmin database. * * @return array */ public function getFromDb() { // Read from phpMyAdmin database, if recent tables is not in session $sql_query = " SELECT `tables` FROM " . $this->_pmaTable . " WHERE `username` = '" . $GLOBALS['cfg']['Server']['user'] . "'"; $return = array(); $result = PMA_queryAsControlUser($sql_query, false); if ($result) { $row = PMA_DBI_fetch_array($result); if (isset($row[0])) { $return = json_decode($row[0], true); } } return $return; }
</th> <th><?php echo $strStatus; ?> </th> <th><?php echo $strShow; ?> </th> </tr> </thead> <tbody> <?php $style = 'odd'; PMA_DBI_data_seek($sql_result, 0); while ($version = PMA_DBI_fetch_array($sql_result)) { if ($version['tracking_active'] == 1) { $version_status = $strTrackingStatusActive; } else { $version_status = $strTrackingStatusNotActive; } if ($version['version'] == $last_version && $version_status == $strTrackingStatusNotActive) { $tracking_active = false; } if ($version['version'] == $last_version && $version_status == $strTrackingStatusActive) { $tracking_active = true; } ?> <tr class="<?php echo $style; ?>
/** * Returns the names of children of type $type present inside this container * This method is overridden by the Node_Database and Node_Table classes * * @param string $type The type of item we are looking for * ('tables', 'views', etc) * @param int $pos The offset of the list within the results * @param string $searchClause A string used to filter the results of the query * * @return array */ public function getData($type, $pos, $searchClause = '') { $maxItems = $GLOBALS['cfg']['MaxNavigationItems']; $retval = array(); $db = $this->realParent()->real_name; $table = $this->real_name; switch ($type) { case 'columns': if (!$GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) { $db = PMA_Util::sqlAddSlashes($db); $table = PMA_Util::sqlAddSlashes($table); $query = "SELECT `COLUMN_NAME` AS `name` "; $query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` "; $query .= "WHERE `TABLE_NAME`='{$table}' "; $query .= "AND `TABLE_SCHEMA`='{$db}' "; $query .= "ORDER BY `COLUMN_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", {$maxItems}"; $retval = PMA_DBI_fetch_result($query); } else { $db = PMA_Util::backquote($db); $table = PMA_Util::backquote($table); $query = "SHOW COLUMNS FROM {$table} FROM {$db}"; $handle = PMA_DBI_try_query($query); if ($handle !== false) { $count = 0; while ($arr = PMA_DBI_fetch_array($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Field']; $count++; } $pos--; } } } break; case 'indexes': $db = PMA_Util::backquote($db); $table = PMA_Util::backquote($table); $query = "SHOW INDEXES FROM {$table} FROM {$db}"; $handle = PMA_DBI_try_query($query); if ($handle !== false) { $count = 0; while ($arr = PMA_DBI_fetch_array($handle)) { if (!in_array($arr['Key_name'], $retval)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Key_name']; $count++; } $pos--; } } } break; case 'triggers': if (!$GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) { $db = PMA_Util::sqlAddSlashes($db); $table = PMA_Util::sqlAddSlashes($table); $query = "SELECT `TRIGGER_NAME` AS `name` "; $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` "; $query .= "WHERE `EVENT_OBJECT_SCHEMA`='{$db}' "; $query .= "AND `EVENT_OBJECT_TABLE`='{$table}' "; $query .= "ORDER BY `TRIGGER_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", {$maxItems}"; $retval = PMA_DBI_fetch_result($query); } else { $db = PMA_Util::backquote($db); $table = PMA_Util::sqlAddSlashes($table); $query = "SHOW TRIGGERS FROM {$db} WHERE `Table` = '{$table}'"; $handle = PMA_DBI_try_query($query); if ($handle !== false) { $count = 0; while ($arr = PMA_DBI_fetch_array($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Trigger']; $count++; } $pos--; } } } break; default: break; } return $retval; }
*/ $url_query = PMA_generate_common_url(isset($db) ? $db : ''); /** * Defines the urls to return to in case of error in a sql statement */ $err_url = 'main.php' . $url_query; /** * Displays the headers */ require_once './libraries/header.inc.php'; /** * Checks for superuser privileges */ $is_superuser = PMA_isSuperuser(); // now, select the mysql db if ($is_superuser) { PMA_DBI_select_db('mysql', $userlink); } $has_binlogs = FALSE; $binlogs = PMA_DBI_try_query('SHOW MASTER LOGS', null, PMA_DBI_QUERY_STORE); if ($binlogs) { if (PMA_DBI_num_rows($binlogs) > 0) { $binary_logs = array(); while ($row = PMA_DBI_fetch_array($binlogs)) { $binary_logs[] = $row[0]; } $has_binlogs = TRUE; } PMA_DBI_free_result($binlogs); } unset($binlogs);
/** * Return UI preferences for this table from phpMyAdmin database. * * @return array */ protected function getUiPrefsFromDb() { $pma_table = PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . "." . PMA_backquote($GLOBALS['cfg']['Server']['table_uiprefs']); // Read from phpMyAdmin database $sql_query = " SELECT `prefs` FROM " . $pma_table . " WHERE `username` = '" . $GLOBALS['cfg']['Server']['user'] . "'" . " AND `db_name` = '" . PMA_sqlAddSlashes($this->db_name) . "'" . " AND `table_name` = '" . PMA_sqlAddSlashes($this->name) . "'"; $row = PMA_DBI_fetch_array(PMA_query_as_controluser($sql_query)); if (isset($row[0])) { return json_decode($row[0], true); } else { return array(); } }
/** * Gets the newest version of a tracking job * (in other words: gets the HEAD version). * * @param string $dbname name of database * @param string $tablename name of table * @param string $statement tracked statement * * @static * * @return int (-1 if no version exists | > 0 if a version exists) */ static public function getVersion($dbname, $tablename, $statement = null) { $sql_query = " SELECT MAX(version) FROM " . self::$pma_table . " WHERE `db_name` = '" . PMA_sqlAddSlashes($dbname) . "' " . " AND `table_name` = '" . PMA_sqlAddSlashes($tablename) . "' "; if ($statement != "") { $sql_query .= PMA_DRIZZLE ? ' AND tracking & ' . self::transformTrackingSet($statement) . ' <> 0' : " AND FIND_IN_SET('" . $statement . "',tracking) > 0" ; } $row = PMA_DBI_fetch_array(PMA_query_as_controluser($sql_query)); return isset($row[0]) ? $row[0] : -1; }
/** * Returns the names of children of type $type present inside this container * This method is overridden by the Node_Database and Node_Table classes * * @param string $type The type of item we are looking for * ('tables', 'views', etc) * @param int $pos The offset of the list within the results * @param string $searchClause A string used to filter the results of the query * * @return array */ public function getData($type, $pos, $searchClause = '') { $maxItems = $GLOBALS['cfg']['MaxNavigationItems']; $retval = array(); $db = $this->real_name; switch ($type) { case 'tables': if (!$GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) { $db = PMA_Util::sqlAddSlashes($db); $query = "SELECT `TABLE_NAME` AS `name` "; $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` "; $query .= "WHERE `TABLE_SCHEMA`='{$db}' "; $query .= "AND `TABLE_TYPE`='BASE TABLE' "; if (!empty($searchClause)) { $query .= "AND `TABLE_NAME` LIKE '%"; $query .= PMA_Util::sqlAddSlashes($searchClause, true); $query .= "%'"; } $query .= "ORDER BY `TABLE_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", {$maxItems}"; $retval = PMA_DBI_fetch_result($query); } else { $query = " SHOW FULL TABLES FROM "; $query .= PMA_Util::backquote($db); $query .= " WHERE `Table_type`='BASE TABLE' "; if (!empty($searchClause)) { $query .= "AND " . PMA_Util::backquote("Tables_in_" . $db); $query .= " LIKE '%" . PMA_Util::sqlAddSlashes($searchClause, true); $query .= "%'"; } $handle = PMA_DBI_try_query($query); if ($handle !== false) { $count = 0; while ($arr = PMA_DBI_fetch_array($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr[0]; $count++; } $pos--; } } } break; case 'views': if (!$GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) { $db = PMA_Util::sqlAddSlashes($db); $query = "SELECT `TABLE_NAME` AS `name` "; $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` "; $query .= "WHERE `TABLE_SCHEMA`='{$db}' "; $query .= "AND `TABLE_TYPE`!='BASE TABLE' "; if (!empty($searchClause)) { $query .= "AND `TABLE_NAME` LIKE '%"; $query .= PMA_Util::sqlAddSlashes($searchClause, true); $query .= "%'"; } $query .= "ORDER BY `TABLE_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", {$maxItems}"; $retval = PMA_DBI_fetch_result($query); } else { $query = "SHOW FULL TABLES FROM "; $query .= PMA_Util::backquote($db); $query .= " WHERE `Table_type`!='BASE TABLE' "; if (!empty($searchClause)) { $query .= "AND " . PMA_Util::backquote("Tables_in_" . $db); $query .= " LIKE '%" . PMA_Util::sqlAddSlashes($searchClause, true); $query .= "%'"; } $handle = PMA_DBI_try_query($query); if ($handle !== false) { $count = 0; while ($arr = PMA_DBI_fetch_array($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr[0]; $count++; } $pos--; } } } break; case 'procedures': if (!$GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) { $db = PMA_Util::sqlAddSlashes($db); $query = "SELECT `ROUTINE_NAME` AS `name` "; $query .= "FROM `INFORMATION_SCHEMA`.`ROUTINES` "; $query .= "WHERE `ROUTINE_SCHEMA`='{$db}'"; $query .= "AND `ROUTINE_TYPE`='PROCEDURE' "; if (!empty($searchClause)) { $query .= "AND `ROUTINE_NAME` LIKE '%"; $query .= PMA_Util::sqlAddSlashes($searchClause, true); $query .= "%'"; } $query .= "ORDER BY `ROUTINE_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", {$maxItems}"; $retval = PMA_DBI_fetch_result($query); } else { $db = PMA_Util::sqlAddSlashes($db); $query = "SHOW PROCEDURE STATUS WHERE `Db`='{$db}' "; if (!empty($searchClause)) { $query .= "AND `Name` LIKE '%"; $query .= PMA_Util::sqlAddSlashes($searchClause, true); $query .= "%'"; } $handle = PMA_DBI_try_query($query); if ($handle !== false) { $count = 0; while ($arr = PMA_DBI_fetch_array($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Name']; $count++; } $pos--; } } } break; case 'functions': if (!$GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) { $db = PMA_Util::sqlAddSlashes($db); $query = "SELECT `ROUTINE_NAME` AS `name` "; $query .= "FROM `INFORMATION_SCHEMA`.`ROUTINES` "; $query .= "WHERE `ROUTINE_SCHEMA`='{$db}' "; $query .= "AND `ROUTINE_TYPE`='FUNCTION' "; if (!empty($searchClause)) { $query .= "AND `ROUTINE_NAME` LIKE '%"; $query .= PMA_Util::sqlAddSlashes($searchClause, true); $query .= "%'"; } $query .= "ORDER BY `ROUTINE_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", {$maxItems}"; $retval = PMA_DBI_fetch_result($query); } else { $db = PMA_Util::sqlAddSlashes($db); $query = "SHOW FUNCTION STATUS WHERE `Db`='{$db}' "; if (!empty($searchClause)) { $query .= "AND `Name` LIKE '%"; $query .= PMA_Util::sqlAddSlashes($searchClause, true); $query .= "%'"; } $handle = PMA_DBI_try_query($query); if ($handle !== false) { $count = 0; while ($arr = PMA_DBI_fetch_array($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Name']; $count++; } $pos--; } } } break; case 'events': if (!$GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) { $db = PMA_Util::sqlAddSlashes($db); $query = "SELECT `EVENT_NAME` AS `name` "; $query .= "FROM `INFORMATION_SCHEMA`.`EVENTS` "; $query .= "WHERE `EVENT_SCHEMA`='{$db}' "; if (!empty($searchClause)) { $query .= "AND `EVENT_NAME` LIKE '%"; $query .= PMA_Util::sqlAddSlashes($searchClause, true); $query .= "%'"; } $query .= "ORDER BY `EVENT_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", {$maxItems}"; $retval = PMA_DBI_fetch_result($query); } else { $db = PMA_Util::backquote($db); $query = "SHOW EVENTS FROM {$db} "; if (!empty($searchClause)) { $query .= "WHERE `Name` LIKE '%"; $query .= PMA_Util::sqlAddSlashes($searchClause, true); $query .= "%'"; } $handle = PMA_DBI_try_query($query); if ($handle !== false) { $count = 0; while ($arr = PMA_DBI_fetch_array($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Name']; $count++; } $pos--; } } } break; default: break; } return $retval; }
<tbody> <?php // Print out information about versions $drop_image_or_text = ''; if (true == $GLOBALS['cfg']['PropertiesIconic']) { $drop_image_or_text .= '<img class="icon" width="16" height="16" src="' . $pmaThemeImage . 'b_drop.png" alt="' . __('Delete tracking data for this table') . '" title="' . __('Delete tracking data for this table') . '" />'; } if ('both' === $GLOBALS['cfg']['PropertiesIconic'] || false === $GLOBALS['cfg']['PropertiesIconic']) { $drop_image_or_text .= __('Drop'); } $style = 'odd'; while ($one_result = PMA_DBI_fetch_array($all_tables_result)) { list($table_name, $version_number) = $one_result; $table_query = ' SELECT * FROM ' . PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' . PMA_backquote($GLOBALS['cfg']['Server']['tracking']) . ' WHERE `db_name` = \'' . PMA_sqlAddslashes($_REQUEST['db']) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($table_name) . '\' AND `version` = \'' . $version_number . '\''; $table_result = PMA_query_as_controluser($table_query); $version_data = PMA_DBI_fetch_array($table_result); if ($version_data['tracking_active'] == 1) { $version_status = __('active'); } else { $version_status = __('not active'); } $tmp_link = 'tbl_tracking.php?' . $url_query . '&table=' . htmlspecialchars($version_data['table_name']); $delete_link = 'db_tracking.php?' . $url_query . '&table=' . htmlspecialchars($version_data['table_name']) . '&delete_tracking=true&'; ?> <tr class="noclick <?php echo $style; ?> "> <td><?php echo htmlspecialchars($version_data['db_name']); ?>
function get_tab_pos() { $stmt = PMA_query_as_cu("SELECT * FROM " . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']), FALSE, PMA_DBI_QUERY_STORE); if ($stmt) { while ($t_p = PMA_DBI_fetch_array($stmt, MYSQL_ASSOC)) { $t_name = $t_p['db_name'] . '.' . $t_p['table_name']; $tab_pos[$t_name]['X'] = $t_p['x']; $tab_pos[$t_name]['Y'] = $t_p['y']; $tab_pos[$t_name]['V'] = $t_p['v']; $tab_pos[$t_name]['H'] = $t_p['h']; } } return isset($tab_pos) ? $tab_pos : NULL; }
/** * Simple test for fetching results of query * * This relies on dummy driver internals * * @return void */ function testFetch() { $this->assertEquals(array('1'), PMA_DBI_fetch_array(0)); }
/** * Gets the record of a tracking job. * * @static * * @param string $dbname name of database * @param string $tablename name of table * @param string $version version number * * @return mixed record DDM log, DDL log, structure snapshot, tracked statements. */ public static function getTrackedData($dbname, $tablename, $version) { if (!isset(self::$pma_table)) { self::init(); } $sql_query = " SELECT * FROM " . self::$pma_table . " WHERE `db_name` = '" . PMA_sqlAddslashes($dbname) . "' "; if (!empty($tablename)) { $sql_query .= " AND `table_name` = '" . PMA_sqlAddslashes($tablename) . "' "; } $sql_query .= " AND `version` = '" . PMA_sqlAddslashes($version) . "' " . " ORDER BY `version` DESC "; $mixed = PMA_DBI_fetch_array(PMA_query_as_controluser($sql_query)); // Parse log $log_schema_entries = explode('# log ', $mixed['schema_sql']); $log_data_entries = explode('# log ', $mixed['data_sql']); $ddl_date_from = $date = date('Y-m-d H:i:s'); $ddlog = array(); $i = 0; // Iterate tracked data definition statements // For each log entry we want to get date, username and statement foreach ($log_schema_entries as $log_entry) { if (trim($log_entry) != '') { $date = substr($log_entry, 0, 19); $username = substr($log_entry, 20, strpos($log_entry, "\n") - 20); if ($i == 0) { $ddl_date_from = $date; } $statement = rtrim(strstr($log_entry, "\n")); $ddlog[] = array('date' => $date, 'username' => $username, 'statement' => $statement); $i++; } } $date_from = $ddl_date_from; $date_to = $ddl_date_to = $date; $dml_date_from = $date_from; $dmlog = array(); $i = 0; // Iterate tracked data manipulation statements // For each log entry we want to get date, username and statement foreach ($log_data_entries as $log_entry) { if (trim($log_entry) != '') { $date = substr($log_entry, 0, 19); $username = substr($log_entry, 20, strpos($log_entry, "\n") - 20); if ($i == 0) { $dml_date_from = $date; } $statement = rtrim(strstr($log_entry, "\n")); $dmlog[] = array('date' => $date, 'username' => $username, 'statement' => $statement); $i++; } } $dml_date_to = $date; // Define begin and end of date range for both logs if (strtotime($ddl_date_from) <= strtotime($dml_date_from)) { $data['date_from'] = $ddl_date_from; } else { $data['date_from'] = $dml_date_from; } if (strtotime($ddl_date_to) >= strtotime($dml_date_to)) { $data['date_to'] = $ddl_date_to; } else { $data['date_to'] = $dml_date_to; } $data['ddlog'] = $ddlog; $data['dmlog'] = $dmlog; $data['tracking'] = $mixed['tracking']; $data['schema_snapshot'] = $mixed['schema_snapshot']; return $data; }