/** * Outputs database header * * @param string Database name * * @return bool Whether it suceeded * * @access public */ function PMA_exportDBHeader($db) { global $crlf; $db = str_replace(' ', '_', $db); $head = '<!--' . $crlf . '- ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\'') . $crlf . '-->' . $crlf . '<' . $db . '>' . $crlf; return PMA_exportOutputHandler($head); }
/** * Builds the SQL search query * * @param string the table name * @param string the string to search * @param integer type of search (1 -> 1 word at least, 2 -> all words, * 3 -> exact string, 4 -> regexp) * * @return array 3 SQL querys (for count, display and delete results) * * @global string the url to return to in case of errors */ function PMA_getSearchSqls($table, $search_str, $search_option) { global $err_url, $charset_connection; // Statement types $sqlstr_select = 'SELECT'; $sqlstr_delete = 'DELETE'; // Fields to select $res = PMA_DBI_query('SHOW ' . (PMA_MYSQL_INT_VERSION >= 40100 ? 'FULL ' : '') . 'FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($GLOBALS['db']) . ';'); while ($current = PMA_DBI_fetch_assoc($res)) { if (PMA_MYSQL_INT_VERSION >= 40100) { list($current['Charset']) = explode('_', $current['Collation']); } $current['Field'] = PMA_backquote($current['Field']); $tblfields[] = $current; } // while PMA_DBI_free_result($res); unset($current, $res); $tblfields_cnt = count($tblfields); // Table to use $sqlstr_from = ' FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($table); // Beginning of WHERE clause $sqlstr_where = ' WHERE'; $search_words = $search_option > 2 ? array($search_str) : explode(' ', $search_str); $search_wds_cnt = count($search_words); $like_or_regex = $search_option == 4 ? 'REGEXP' : 'LIKE'; $automatic_wildcard = $search_option < 3 ? '%' : ''; for ($i = 0; $i < $search_wds_cnt; $i++) { // Eliminates empty values // In MySQL 4.1, if a field has no collation we get NULL in Charset // but in MySQL 5.0.x we get '' if (!empty($search_words[$i])) { for ($j = 0; $j < $tblfields_cnt; $j++) { if (PMA_MYSQL_INT_VERSION >= 40100 && $tblfields[$j]['Charset'] != $charset_connection && $tblfields[$j]['Charset'] != 'NULL' && $tblfields[$j]['Charset'] != '') { $prefix = 'CONVERT(_utf8 '; $suffix = ' USING ' . $tblfields[$j]['Charset'] . ') COLLATE ' . $tblfields[$j]['Collation']; } else { $prefix = $suffix = ''; } $thefieldlikevalue[] = $tblfields[$j]['Field'] . ' ' . $like_or_regex . ' ' . $prefix . '\'' . $automatic_wildcard . $search_words[$i] . $automatic_wildcard . '\'' . $suffix; } // end for $fieldslikevalues[] = $search_wds_cnt > 1 ? '(' . implode(' OR ', $thefieldlikevalue) . ')' : implode(' OR ', $thefieldlikevalue); unset($thefieldlikevalue); } // end if } // end for $implode_str = $search_option == 1 ? ' OR ' : ' AND '; $sqlstr_where .= ' ' . implode($implode_str, $fieldslikevalues); unset($fieldslikevalues); // Builds complete queries $sql['select_fields'] = $sqlstr_select . ' * ' . $sqlstr_from . $sqlstr_where; // here, I think we need to still use the COUNT clause, even for // VIEWs, anyway we have a WHERE clause that should limit results $sql['select_count'] = $sqlstr_select . ' COUNT(*) AS count' . $sqlstr_from . $sqlstr_where; $sql['delete'] = $sqlstr_delete . $sqlstr_from . $sqlstr_where; return $sql; }
function PMA_analyseShowGrant($rs_usr, &$is_create_db_priv, &$db_to_create, &$is_reload_priv, &$dbs_where_create_table_allowed) { $re0 = '(^|(\\\\\\\\)+|[^\\])'; // non-escaped wildcards $re1 = '(^|[^\\])(\\\\)+'; // escaped wildcards while ($row = PMA_DBI_fetch_row($rs_usr)) { $show_grants_dbname = substr($row[0], strpos($row[0], ' ON ') + 4, strpos($row[0], '.', strpos($row[0], ' ON ')) - strpos($row[0], ' ON ') - 4); $show_grants_dbname = ereg_replace('^`(.*)`', '\\1', $show_grants_dbname); $show_grants_str = substr($row[0], 6, strpos($row[0], ' ON ') - 6); if ($show_grants_str == 'RELOAD') { $is_reload_priv = true; } /** * @todo if we find CREATE VIEW but not CREATE, do not offer * the create database dialog box */ if ($show_grants_str == 'ALL' || $show_grants_str == 'ALL PRIVILEGES' || $show_grants_str == 'CREATE' || strpos($show_grants_str, 'CREATE,') !== false) { if ($show_grants_dbname == '*') { // a global CREATE privilege $is_create_db_priv = true; $is_reload_priv = true; $db_to_create = ''; $dbs_where_create_table_allowed[] = '*'; break; } else { // this array may contain wildcards $dbs_where_create_table_allowed[] = $show_grants_dbname; // before MySQL 4.1.0, we cannot use backquotes around a dbname // for the USE command, so the USE will fail if the dbname contains // a "-" and we cannot detect if such a db already exists; // since 4.1.0, we need to use backquotes if the dbname contains a "-" // in a USE command if (PMA_MYSQL_INT_VERSION > 40100) { $dbname_to_test = PMA_backquote($show_grants_dbname); } else { $dbname_to_test = $show_grants_dbname; } if (ereg($re0 . '%|_', $show_grants_dbname) && !ereg('\\\\%|\\\\_', $show_grants_dbname) || !PMA_DBI_try_query('USE ' . ereg_replace($re1 . '(%|_)', '\\1\\3', $dbname_to_test), null, PMA_DBI_QUERY_STORE) && substr(PMA_DBI_getError(), 1, 4) != 1044) { $db_to_create = ereg_replace($re0 . '%', '\\1...', ereg_replace($re0 . '_', '\\1?', $show_grants_dbname)); $db_to_create = ereg_replace($re1 . '(%|_)', '\\1\\3', $db_to_create); $is_create_db_priv = true; /** * @todo collect $db_to_create into an array, to display a * drop-down in the "Create new database" dialog */ // we don't break, we want all possible databases //break; } // end if } // end elseif } // end if } // end while }
public function __construct() { if (strlen($GLOBALS['cfg']['Server']['pmadb']) && strlen($GLOBALS['cfg']['Server']['recent'])) { $this->pma_table = PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . "." . PMA_backquote($GLOBALS['cfg']['Server']['recent']); } $server_id = $GLOBALS['server']; if (!isset($_SESSION['tmp_user_values']['recent_tables'][$server_id])) { $_SESSION['tmp_user_values']['recent_tables'][$server_id] = isset($this->pma_table) ? $this->getFromDb() : array(); } $this->tables =& $_SESSION['tmp_user_values']['recent_tables'][$server_id]; }
/** * Format a string so it can be a string inside JavaScript code inside an * eventhandler (onclick, onchange, on..., ). * This function is used to displays a javascript confirmation box for * "DROP/DELETE/ALTER" queries. * * @param string $a_string the string to format * @param boolean $add_backquotes whether to add backquotes to the string or not * * @return string the formatted string * * @access public */ function PMA_jsFormat($a_string = '', $add_backquotes = true) { if (is_string($a_string)) { $a_string = htmlspecialchars($a_string); $a_string = PMA_escapeJsString($a_string); // Needed for inline javascript to prevent some browsers // treating it as a anchor $a_string = str_replace('#', '\\#', $a_string); } return $add_backquotes ? PMA_backquote($a_string) : $a_string; }
/** * Format a string so it can be a string inside JavaScript code inside an * eventhandler (onclick, onchange, on..., ). * This function is used to displays a javascript confirmation box for * "DROP/DELETE/ALTER" queries. * * @uses PMA_escapeJsString() * @uses PMA_backquote() * @uses is_string() * @uses htmlspecialchars() * @uses str_replace() * @param string $a_string the string to format * @param boolean $add_backquotes whether to add backquotes to the string or not * * @return string the formatted string * * @access public */ function PMA_jsFormat($a_string = '', $add_backquotes = true) { if (is_string($a_string)) { $a_string = htmlspecialchars($a_string); $a_string = PMA_escapeJsString($a_string); /** * @todo what is this good for? */ $a_string = str_replace('#', '\\#', $a_string); } return $add_backquotes ? PMA_backquote($a_string) : $a_string; }
/** * Builds the SQL search query * * @param string the table name * @param string the string to search * @param integer type of search (1 -> 1 word at least, 2 -> all words, * 3 -> exact string, 4 -> regexp) * * @return array 3 SQL querys (for count, display and delete results) * * @global string the url to retun to in case of errors */ function PMA_getSearchSqls($table, $search_str, $search_option) { global $err_url; // Statement types $sqlstr_select = 'SELECT'; $sqlstr_delete = 'DELETE'; // Fields to select $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($GLOBALS['db']); $res = @PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, FALSE, $err_url); $res_cnt = $res ? mysql_num_rows($res) : 0; for ($i = 0; $i < $res_cnt; $i++) { $tblfields[] = PMA_backquote(PMA_mysql_result($res, $i, 'field')); } // end if $sqlstr_fieldstoselect = ' ' . implode(', ', $tblfields); $tblfields_cnt = count($tblfields); if ($res) { mysql_free_result($res); } // Table to use $sqlstr_from = ' FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($table); // Beginning of WHERE clause $sqlstr_where = ' WHERE'; $search_words = $search_option > 2 ? array($search_str) : explode(' ', $search_str); $search_wds_cnt = count($search_words); $like_or_regex = $search_option == 4 ? 'REGEXP' : 'LIKE'; $automatic_wildcard = $search_option < 3 ? '%' : ''; for ($i = 0; $i < $search_wds_cnt; $i++) { // Elimines empty values if (!empty($search_words[$i])) { for ($j = 0; $j < $tblfields_cnt; $j++) { $thefieldlikevalue[] = $tblfields[$j] . ' ' . $like_or_regex . ' \'' . $automatic_wildcard . $search_words[$i] . $automatic_wildcard . '\''; } // end for $fieldslikevalues[] = $search_wds_cnt > 1 ? '(' . implode(' OR ', $thefieldlikevalue) . ')' : implode(' OR ', $thefieldlikevalue); unset($thefieldlikevalue); } // end if } // end for $implode_str = $search_option == 1 ? ' OR ' : ' AND '; $sqlstr_where .= ' ' . implode($implode_str, $fieldslikevalues); unset($fieldslikevalues); // Builds complete queries $sql['select_fields'] = $sqlstr_select . $sqlstr_fieldstoselect . $sqlstr_from . $sqlstr_where; $sql['select_count'] = $sqlstr_select . ' COUNT(*) AS count' . $sqlstr_from . $sqlstr_where; $sql['delete'] = $sqlstr_delete . $sqlstr_from . $sqlstr_where; return $sql; }
function PMA_bkq($a_name) { if (is_array($a_name)) { foreach ($a_name as &$data) { $data = PMA_backquote($data, $do_it); } return $a_name; } // '0' is also empty for php :-( if (strlen($a_name) && $a_name !== '*') { return '`' . str_replace('`', '``', $a_name) . '`'; } else { return $a_name; } }
function PMA_DBI_get_fields($database, $table, $link = NULL) { if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; } else { return FALSE; } } $result = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table), $link); $fields = array(); while ($row = PMA_DBI_fetch_assoc($result)) { $fields[] = $row; } return $fields; }
/** * Saves user preferences * * @param array $config_array configuration array * * @return true|PMA_Message */ function PMA_save_userprefs(array $config_array) { $cfgRelation = PMA_getRelationsParam(); $server = isset($GLOBALS['server']) ? $GLOBALS['server'] : $GLOBALS['cfg']['ServerDefault']; $cache_key = 'server_' . $server; if (!$cfgRelation['userconfigwork']) { // no pmadb table, use session storage $_SESSION['userconfig'] = array('db' => $config_array, 'ts' => time()); if (isset($_SESSION['cache'][$cache_key]['userprefs'])) { unset($_SESSION['cache'][$cache_key]['userprefs']); } return true; } // save configuration to pmadb $query_table = PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['userconfig']); $query = ' SELECT `username` FROM ' . $query_table . ' WHERE `username` = \'' . PMA_sqlAddSlashes($cfgRelation['user']) . '\''; $has_config = PMA_DBI_fetch_value($query, 0, 0, $GLOBALS['controllink']); $config_data = json_encode($config_array); if ($has_config) { $query = ' UPDATE ' . $query_table . ' SET `config_data` = \'' . PMA_sqlAddSlashes($config_data) . '\' WHERE `username` = \'' . PMA_sqlAddSlashes($cfgRelation['user']) . '\''; } else { $query = ' INSERT INTO ' . $query_table . ' (`username`, `config_data`) VALUES (\'' . PMA_sqlAddSlashes($cfgRelation['user']) . '\', \'' . PMA_sqlAddSlashes($config_data) . '\')'; } if (isset($_SESSION['cache'][$cache_key]['userprefs'])) { unset($_SESSION['cache'][$cache_key]['userprefs']); } if (!PMA_DBI_try_query($query, $GLOBALS['controllink'])) { $message = PMA_Message::error(__('Could not save configuration')); $message->addMessage('<br /><br />'); $message->addMessage(PMA_Message::rawError(PMA_DBI_getError($GLOBALS['controllink']))); return $message; } return true; }
/** * Inserts existing entries in a PMA_* table by reading a value from an old entry * * @param string The array index, which Relation feature to check * ('relwork', 'commwork', ...) * @param string The array index, which PMA-table to update * ('bookmark', 'relation', ...) * @param array Which fields will be SELECT'ed from the old entry * @param array Which fields will be used for the WHERE query * (array('FIELDNAME' => 'FIELDVALUE')) * @param array Which fields will be used as new VALUES. These are the important * keys which differ from the old entry. * (array('FIELDNAME' => 'NEW FIELDVALUE')) * @global string relation variable * * @author Garvin Hicking <*****@*****.**> */ function PMA_duplicate_table($work, $pma_table, $get_fields, $where_fields, $new_fields) { global $cfgRelation; $last_id = -1; if ($cfgRelation[$work]) { $select_parts = array(); $row_fields = array(); foreach ($get_fields as $nr => $get_field) { $select_parts[] = PMA_backquote($get_field); $row_fields[$get_field] = 'cc'; } $where_parts = array(); foreach ($where_fields as $_where => $_value) { $where_parts[] = PMA_backquote($_where) . ' = \'' . PMA_sqlAddslashes($_value) . '\''; } $new_parts = array(); $new_value_parts = array(); foreach ($new_fields as $_where => $_value) { $new_parts[] = PMA_backquote($_where); $new_value_parts[] = PMA_sqlAddslashes($_value); } $table_copy_query = 'SELECT ' . implode(', ', $select_parts) . ' FROM ' . PMA_backquote($cfgRelation[$pma_table]) . ' WHERE ' . implode(' AND ', $where_parts); $table_copy_rs = PMA_query_as_cu($table_copy_query); while ($table_copy_row = @PMA_mysql_fetch_array($table_copy_rs)) { $value_parts = array(); foreach ($table_copy_row as $_key => $_val) { if (isset($row_fields[$_key]) && $row_fields[$_key] == 'cc') { $value_parts[] = PMA_sqlAddslashes($_val); } } $new_table_query = 'INSERT IGNORE INTO ' . PMA_backquote($cfgRelation[$pma_table]) . ' (' . implode(', ', $select_parts) . ', ' . implode(', ', $new_parts) . ')' . ' VALUES ' . ' (\'' . implode('\', \'', $value_parts) . '\', \'' . implode('\', \'', $new_value_parts) . '\')'; $new_table_rs = PMA_query_as_cu($new_table_query); $last_id = @function_exists('mysql_insert_id') ? @mysql_insert_id() : -1; } // end while return $last_id; } return true; }
/** * This function is called from one of the other functions in this file * and it completes the handling of the export functionality. * * @param string $item_name The name of the item that we are exporting * @param string $export_data The SQL query to create the requested item */ function PMA_RTE_handleExport($item_name, $export_data) { global $db; $item_name = htmlspecialchars(PMA_backquote($_GET['item_name'])); if ($export_data !== false) { $export_data = '<textarea cols="40" rows="15" style="width: 100%;">' . htmlspecialchars(trim($export_data)) . '</textarea>'; $title = sprintf(PMA_RTE_getWord('export'), $item_name); if ($GLOBALS['is_ajax_request'] == true) { $extra_data = array('title' => $title); PMA_ajaxResponse($export_data, true, $extra_data); } else { echo "<fieldset>\n" . "<legend>{$title}</legend>\n" . $export_data . "</fieldset>\n"; } } else { $_db = htmlspecialchars(PMA_backquote($db)); $response = __('Error in Processing Request') . ' : ' . sprintf(PMA_RTE_getWord('not_found'), $item_name, $_db); $response = PMA_message::error($response); if ($GLOBALS['is_ajax_request'] == true) { PMA_ajaxResponse($response, false); } else { $response->display(); } } }
/** * Set a single mimetype to a certain value. * * @param string the name of the db * @param string the name of the table * @param string the name of the column * @param string the mimetype of the column * @param string the transformation of the column * @param string the transformation options of the column * @param string (optional) force delete, will erase any existing comments for this column * * @return boolean true, if comment-query was made. * * @global array the list of relations settings * * @access public */ function PMA_setMIME($db, $table, $key, $mimetype, $transformation, $transformation_options, $forcedelete = false) { global $cfgRelation; $test_qry = 'SELECT mimetype, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\''; $test_rs = PMA_query_as_cu($test_qry, TRUE, PMA_DBI_QUERY_STORE); if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { $row = @PMA_DBI_fetch_assoc($test_rs); PMA_DBI_free_result($test_rs); unset($test_rs); if (!$forcedelete && (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0 || strlen($row['comment']) > 0)) { $upd_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' SET mimetype = \'' . PMA_sqlAddslashes($mimetype) . '\',' . ' transformation = \'' . PMA_sqlAddslashes($transformation) . '\',' . ' transformation_options = \'' . PMA_sqlAddslashes($transformation_options) . '\'' . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\''; } else { $upd_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\''; } } elseif (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0) { $upd_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($db) . '\',' . '\'' . PMA_sqlAddslashes($table) . '\',' . '\'' . PMA_sqlAddslashes($key) . '\',' . '\'' . PMA_sqlAddslashes($mimetype) . '\',' . '\'' . PMA_sqlAddslashes($transformation) . '\',' . '\'' . PMA_sqlAddslashes($transformation_options) . '\')'; } if (isset($upd_query)) { $upd_rs = PMA_query_as_cu($upd_query); PMA_DBI_free_result($upd_rs); unset($upd_rs); return true; } else { return false; } }
/** * Show index data and prepare returned collection array for index * key checks. * * @param string The tablename * @param array Referenced Array of indexes * @param array Referenced info array * @param array Referenced data array * @param boolean Output HTML code, or just return collection array? * * @access public * @return array Index collection array * @author Garvin Hicking (pma@supergarv.de) */ function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data, $display_html = true) { $idx_collection = array(); foreach ($indexes as $index_no => $index_name) { if ($display_html) { $cell_bgd = $index_no % 2 ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']; $index_td = ' <td bgcolor="' . $cell_bgd . '" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n"; echo ' <tr>' . "\n"; echo $index_td . ' ' . htmlspecialchars($index_name) . "\n" . ' </td>' . "\n"; } if (PMA_MYSQL_INT_VERSION < 40002 && $indexes_info[$index_name]['Comment'] == 'FULLTEXT' || PMA_MYSQL_INT_VERSION >= 40002 && $indexes_info[$index_name]['Index_type'] == 'FULLTEXT') { $index_type = 'FULLTEXT'; } else { if ($index_name == 'PRIMARY') { $index_type = 'PRIMARY'; } else { if ($indexes_info[$index_name]['Non_unique'] == '0') { $index_type = 'UNIQUE'; } else { $index_type = 'INDEX'; } } } if ($display_html) { echo $index_td . ' ' . $index_type . "\n" . ' </td>' . "\n"; echo str_replace('">' . "\n", '" align="right">' . "\n", $index_td) . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ? $indexes_info[$index_name]['Cardinality'] : $GLOBALS['strNone']) . ' ' . "\n" . ' </td>' . "\n"; echo $index_td . ' <a href="tbl_indexes.php?' . $GLOBALS['url_query'] . '&index=' . urlencode($index_name) . '">' . $GLOBALS['edit_link_text'] . '</a>' . "\n" . ' </td>' . "\n"; if ($index_name == 'PRIMARY') { $local_query = urlencode('ALTER TABLE ' . PMA_backquote($table) . ' DROP PRIMARY KEY'); $js_msg = 'ALTER TABLE ' . PMA_jsFormat($table) . ' DROP PRIMARY KEY'; $zero_rows = urlencode($GLOBALS['strPrimaryKeyHasBeenDropped']); } else { $local_query = urlencode('ALTER TABLE ' . PMA_backquote($table) . ' DROP INDEX ' . PMA_backquote($index_name)); $js_msg = 'ALTER TABLE ' . PMA_jsFormat($table) . ' DROP INDEX ' . PMA_jsFormat($index_name); $zero_rows = urlencode(sprintf($GLOBALS['strIndexHasBeenDropped'], htmlspecialchars($index_name))); } echo $index_td . ' <a href="sql.php?' . $GLOBALS['url_query'] . '&sql_query=' . $local_query . '&zero_rows=' . $zero_rows . '" onclick="return confirmLink(this, \'' . $js_msg . '\')">' . $GLOBALS['drop_link_text'] . '</a>' . "\n" . ' </td>' . "\n"; } foreach ($indexes_info[$index_name]['Sequences'] as $row_no => $seq_index) { $col_name = $indexes_data[$index_name][$seq_index]['Column_name']; if ($row_no == 0) { if (isset($idx_collection[$index_type][$col_name])) { $idx_collection[$index_type][$col_name]++; } else { $idx_collection[$index_type][$col_name] = 1; } if (isset($idx_collection['ALL'][$col_name])) { $idx_collection['ALL'][$col_name]++; } else { $idx_collection['ALL'][$col_name] = 1; } } if ($display_html) { if ($row_no > 0) { echo ' <tr>' . "\n"; } if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) { echo ' <td bgcolor="' . $cell_bgd . '">' . "\n" . ' ' . $col_name . "\n" . ' </td>' . "\n"; echo ' <td align="right" bgcolor="' . $cell_bgd . '">' . "\n" . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n" . ' </td>' . "\n"; echo ' </tr>' . "\n"; } else { echo ' <td bgcolor="' . $cell_bgd . '" colspan="2">' . "\n" . ' ' . htmlspecialchars($col_name) . "\n" . ' </td>' . "\n"; echo ' </tr>' . "\n"; } } } // end while } // end while return $idx_collection; }
echo "\n"; require_once './libraries/footer.inc.php'; } else { // end if (no row returned) $meta = PMA_DBI_get_fields_meta($result[$key_id]); list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true); if (!empty($unique_condition)) { $found_unique_key = true; } unset($unique_condition, $tmp_clause_is_unique); } } } else { // no primary key given, just load first row - but what happens if table is empty? $insert_mode = true; $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE); $rows = array_fill(0, $cfg['InsertRows'], false); } // <*****@*****.**> // retrieve keys into foreign fields, if any $foreigners = PMA_getForeigners($db, $table); /** * Displays the form */ // loic1: autocomplete feature of IE kills the "onchange" event handler and it // must be replaced by the "onpropertychange" one in this case $chg_evt_handler = PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7 ? 'onpropertychange' : 'onchange'; // Had to put the URI because when hosted on an https server, // some browsers send wrongly this form to the http server. if ($cfg['CtrlArrowsMoving']) { ?>
"> <td colspan="3"> <?php echo '<a href="pdf_pages.php?' . $takeaway . '">'; if ($cfg['PropertiesIconic']) { echo '<img src="' . $pmaThemeImage . 'b_edit.png" border="0" width="16" height="16" hspace="2" align="middle" />'; } echo '' . $strEditPDFPages . '</a>'; ?> </td> </tr> <!-- PDF schema --> <?php // We only show this if we find something in the new pdf_pages table $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''; $test_rs = PMA_query_as_cu($test_query, NULL, PMA_DBI_QUERY_STORE); if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { ?> <tr bgcolor="<?php echo $cfg['BgcolorTwo']; ?> "> <td colspan="3"> <?php echo PMA_generate_common_hidden_inputs($db); if ($cfg['PropertiesIconic']) { echo '<img src="' . $pmaThemeImage . 'b_view.png" border="0" width="16" height="16" hspace="2" align="middle" />'; } echo $strDisplayPDF; ?>
// end while // get rid of last , $valuelist = preg_replace('@, $@', '', $valuelist); // Builds the sql query if ($is_insert) { if (empty($query)) { // first inserted row -> prepare template $fieldlist = preg_replace('@, $@', '', $fieldlist); $query = array('INSERT INTO ' . PMA_backquote($table) . ' (' . $fieldlist . ') VALUES '); } // append current values $query[0] .= '(' . $valuelist . '), '; $message = $strInsertedRows . ' '; } elseif (!empty($valuelist)) { // build update query $query[] = 'UPDATE ' . PMA_backquote($table) . ' SET ' . $valuelist . ' WHERE' . $primary_key . ' LIMIT 1'; $message = $strAffectedRows . ' '; } } // end for // trim last , from insert query if ($is_insert) { $query[0] = preg_replace('@, $@', '', $query[0]); } if (empty($valuelist) && empty($query)) { // No change -> move back to the calling script $message = $strNoModification; if ($is_gotofile) { $js_to_run = 'functions.js'; require_once './libraries/header.inc.php'; require './' . PMA_securePath($goto);
/** * Function to generate unique condition for specified row. * * @param resource handle for current query * @param integer number of fields * @param array meta information about fields * @param array current row * * @access public * @author Michal Cihar (michal@cihar.com) * @return string calculated condition */ function PMA_getUvaCondition($handle, $fields_cnt, $fields_meta, $row) { $primary_key = ''; $unique_key = ''; $uva_nonprimary_condition = ''; for ($i = 0; $i < $fields_cnt; ++$i) { $field_flags = PMA_DBI_field_flags($handle, $i); $meta = $fields_meta[$i]; // do not use an alias in a condition $column_for_condition = $meta->name; if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) { foreach ($analyzed_sql[0]['select_expr'] as $select_expr_position => $select_expr) { $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias']; if (!empty($alias)) { $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column']; if ($alias == $meta->name) { $column_for_condition = $true_column; } // end if } // end if } // end while } // to fix the bug where float fields (primary or not) // can't be matched because of the imprecision of // floating comparison, use CONCAT // (also, the syntax "CONCAT(field) IS NULL" // that we need on the next "if" will work) if ($meta->type == 'real') { $condition = ' CONCAT(' . PMA_backquote($column_for_condition) . ') '; } else { // string and blob fields have to be converted using // the system character set (always utf8) since // mysql4.1 can use different charset for fields. if (PMA_MYSQL_INT_VERSION >= 40100 && ($meta->type == 'string' || $meta->type == 'blob')) { $condition = ' CONVERT(' . PMA_backquote($column_for_condition) . ' USING utf8) '; } else { $condition = ' ' . PMA_backquote($column_for_condition) . ' '; } } // end if... else... if (!isset($row[$i]) || is_null($row[$i])) { $condition .= 'IS NULL AND'; } else { // timestamp is numeric on some MySQL 4.1 if ($meta->numeric && $meta->type != 'timestamp') { $condition .= '= ' . $row[$i] . ' AND'; } elseif ($meta->type == 'blob' && stristr($field_flags, 'BINARY') && !empty($row[$i])) { // use a CAST if possible, to avoid problems // if the field contains wildcard characters % or _ if (PMA_MYSQL_INT_VERSION < 40002) { $condition .= 'LIKE 0x' . bin2hex($row[$i]) . ' AND'; } else { $condition .= '= CAST(0x' . bin2hex($row[$i]) . ' AS BINARY) AND'; } } else { $condition .= '= \'' . PMA_sqlAddslashes($row[$i], FALSE, TRUE) . '\' AND'; } } if ($meta->primary_key > 0) { $primary_key .= $condition; } else { if ($meta->unique_key > 0) { $unique_key .= $condition; } } $uva_nonprimary_condition .= $condition; } // end for // Correction uva 19991216: prefer primary or unique keys // for condition, but use conjunction of all values if no // primary key if ($primary_key) { $uva_condition = $primary_key; } else { if ($unique_key) { $uva_condition = $unique_key; } else { $uva_condition = $uva_nonprimary_condition; } } return preg_replace('|\\s?AND$|', '', $uva_condition); }
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $dummy) { global $cfgRelation; /** * Get the unique keys in the table */ $keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db); $keys_result = PMA_DBI_query($keys_query); $unique_keys = array(); while ($key = PMA_DBI_fetch_assoc($keys_result)) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } PMA_DBI_free_result($keys_result); /** * Gets fields properties */ PMA_DBI_select_db($db); $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table); $result = PMA_DBI_query($local_query); $fields_cnt = PMA_DBI_num_rows($result); // Check if we can use Relations (Mike Beck) if ($do_relation && !empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table); if ($res_rel && count($res_rel) > 0) { $have_rel = TRUE; } else { $have_rel = FALSE; } } else { $have_rel = FALSE; } // end if /** * Displays the table structure */ $buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strStructure'] . ': ' . $table . $crlf . '%' . $crlf . ' \\begin{longtable}{'; if (!PMA_exportOutputHandler($buffer)) { return FALSE; } $columns_cnt = 4; $alignment = '|l|c|c|c|'; if ($do_relation && $have_rel) { $columns_cnt++; $alignment .= 'l|'; } if ($do_comments && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) { $columns_cnt++; $alignment .= 'l|'; } if ($do_mime && $cfgRelation['mimework']) { $columns_cnt++; $alignment .= 'l|'; } $buffer = $alignment . '} ' . $crlf; $header = ' \\hline '; $header .= '\\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strField'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strType'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strNull'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strDefault'] . '}}'; if ($do_relation && $have_rel) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strLinksTo'] . '}}'; } if ($do_comments && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strComments'] . '}}'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}'; $mime_map = PMA_getMIME($db, $table, true); } $local_buffer = PMA_texEscape($table); // Table caption for first page and label if (isset($GLOBALS['latex_caption'])) { $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_caption']) . '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_structure_label']) . '} \\\\' . $crlf; } $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf; // Table caption on next pages if (isset($GLOBALS['latex_caption'])) { $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_continued_caption']) . '} \\\\ ' . $crlf; } $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return FALSE; } while ($row = PMA_DBI_fetch_assoc($result)) { $type = $row['Type']; // reformat mysql query output - staybyte - 9. June 2001 // loic1: set or enum types: slashes single quotes inside options if (eregi('^(set|enum)\\((.+)\\)$', $type, $tmp)) { $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1); $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')'; $type_nowrap = ''; $binary = 0; $unsigned = 0; $zerofill = 0; } else { $type_nowrap = ' nowrap="nowrap"'; $type = eregi_replace('BINARY', '', $type); $type = eregi_replace('ZEROFILL', '', $type); $type = eregi_replace('UNSIGNED', '', $type); if (empty($type)) { $type = ' '; } $binary = eregi('BINARY', $row['Type']); $unsigned = eregi('UNSIGNED', $row['Type']); $zerofill = eregi('ZEROFILL', $row['Type']); } if (!isset($row['Default'])) { if ($row['Null'] != '') { $row['Default'] = 'NULL'; } } else { $row['Default'] = $row['Default']; } $field_name = $row['Field']; $local_buffer = $field_name . "" . $type . "" . ($row['Null'] == '' ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . "" . (isset($row['Default']) ? $row['Default'] : ''); if ($do_relation && $have_rel) { $local_buffer .= ""; if (isset($res_rel[$field_name])) { $local_buffer .= $res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')'; } } if ($do_comments && $cfgRelation['commwork']) { $local_buffer .= ""; if (isset($comments[$field_name])) { $local_buffer .= $comments[$field_name]; } } if ($do_mime && $cfgRelation['mimework']) { $local_buffer .= ""; if (isset($mime_map[$field_name])) { $local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']); } } $local_buffer = PMA_texEscape($local_buffer); if ($row['Key'] == 'PRI') { $pos = strpos($local_buffer, ""); $local_buffer = '\\textit{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos); } if (in_array($field_name, $unique_keys)) { $pos = strpos($local_buffer, ""); $local_buffer = '\\textbf{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos); } $buffer = str_replace("", ' & ', $local_buffer); $buffer .= ' \\\\ \\hline ' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return FALSE; } } // end while PMA_DBI_free_result($result); $buffer = ' \\end{longtable}' . $crlf; return PMA_exportOutputHandler($buffer); }
} if (strlen($ldi_escaped) > 0) { $sql .= ' ESCAPED BY \'' . PMA_sqlAddslashes($ldi_escaped) . '\''; } if (strlen($ldi_new_line) > 0) { if ($ldi_new_line == 'auto') { $ldi_new_line = PMA_whichCrlf() == "\n" ? '\\n' : '\\r\\n'; } $sql .= ' LINES TERMINATED BY \'' . $ldi_new_line . '\''; } if ($skip_queries > 0) { $sql .= ' IGNORE ' . $skip_queries . ' LINES'; $skip_queries = 0; } if (strlen($ldi_columns) > 0) { $sql .= ' ('; $tmp = preg_split('/,( ?)/', $ldi_columns); $cnt_tmp = count($tmp); for ($i = 0; $i < $cnt_tmp; $i++) { if ($i > 0) { $sql .= ', '; } /* Trim also `, if user already included backquoted fields */ $sql .= PMA_backquote(trim($tmp[$i], " \t\r\n\v`")); } // end for $sql .= ')'; } PMA_importRunQuery($sql, $sql); PMA_importRunQuery(); $finished = TRUE;
" onclick="resetDrag();" /> </form> <div id="pdflayout" class="pdflayout" style="visibility: hidden;"> <?php foreach ($array_sh_page as $key => $temp_sh_page) { $drag_x = $temp_sh_page['x']; $drag_y = $temp_sh_page['y']; $draginit .= ' Drag.init(getElement("table_' . $i . '"), null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n"; $draginit .= ' getElement("table_' . $i . '").onDrag = function (x, y) { document.edcoord.elements["c_table_' . $i . '[x]"].value = parseInt(x); document.edcoord.elements["c_table_' . $i . '[y]"].value = parseInt(y) }' . "\n"; $draginit .= ' getElement("table_' . $i . '").style.left = "' . $drag_x . 'px";' . "\n"; $draginit .= ' getElement("table_' . $i . '").style.top = "' . $drag_y . 'px";' . "\n"; $reset_draginit .= ' getElement("table_' . $i . '").style.left = "2px";' . "\n"; $reset_draginit .= ' getElement("table_' . $i . '").style.top = "' . 15 * $i . 'px";' . "\n"; $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n"; $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . 15 * $i . '"' . "\n"; $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($temp_sh_page['table_name']) . ' FROM ' . PMA_backquote($db); $fields_rs = PMA_DBI_query($local_query); unset($local_query); $fields_cnt = PMA_DBI_num_rows($fields_rs); echo '<div id="table_' . $i . '" class="pdflayout_table"><u>' . $temp_sh_page['table_name'] . '</u>'; if (isset($with_field_names)) { while ($row = PMA_DBI_fetch_assoc($fields_rs)) { echo '<br />' . htmlspecialchars($row['Field']) . "\n"; } } echo '</div>' . "\n"; PMA_DBI_free_result($fields_rs); unset($fields_rs); $i++; } ?>
$db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';'); // Blending out tables in use if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) { while ($tmp = PMA_DBI_fetch_row($db_info_result)) { // if in use memorize tablename if (preg_match('@in_use=[1-9]+@i', $tmp[1])) { $sot_cache[$tmp[0]] = true; } } PMA_DBI_free_result($db_info_result); if (isset($sot_cache)) { $db_info_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';', null, PMA_DBI_QUERY_STORE); if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) { while ($tmp = PMA_DBI_fetch_row($db_info_result)) { if (!isset($sot_cache[$tmp[0]])) { $sts_result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\';'); $sts_tmp = PMA_DBI_fetch_assoc($sts_result); PMA_DBI_free_result($sts_result); unset($sts_result); if (!isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) { $sts_tmp['Type'] =& $sts_tmp['Engine']; } if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB'] && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) { continue; } if ($cfg['ShowTooltip']) { PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp); } $tables[$sts_tmp['Name']] = $sts_tmp; } else { // table in use
/** * Displays the privileges form table * * @param string $db the database * @param string $table the table * @param boolean $submit wheather to display the submit button or not * * @global array $cfg the phpMyAdmin configuration * @global ressource $user_link the database connection * * @return void */ function PMA_displayPrivTable($db = '*', $table = '*', $submit = true) { global $random_n; if ($db == '*') { $table = '*'; } if (isset($GLOBALS['username'])) { $username = $GLOBALS['username']; $hostname = $GLOBALS['hostname']; if ($db == '*') { $sql_query = "SELECT * FROM `mysql`.`user`" ." WHERE `User` = '" . PMA_sqlAddSlashes($username) . "'" ." AND `Host` = '" . PMA_sqlAddSlashes($hostname) . "';"; } elseif ($table == '*') { $sql_query = "SELECT * FROM `mysql`.`db`" ." WHERE `User` = '" . PMA_sqlAddSlashes($username) . "'" ." AND `Host` = '" . PMA_sqlAddSlashes($hostname) . "'" ." AND '" . PMA_unescape_mysql_wildcards($db) . "'" ." LIKE `Db`;"; } else { $sql_query = "SELECT `Table_priv`" ." FROM `mysql`.`tables_priv`" ." WHERE `User` = '" . PMA_sqlAddSlashes($username) . "'" ." AND `Host` = '" . PMA_sqlAddSlashes($hostname) . "'" ." AND `Db` = '" . PMA_unescape_mysql_wildcards($db) . "'" ." AND `Table_name` = '" . PMA_sqlAddSlashes($table) . "';"; } $row = PMA_DBI_fetch_single_row($sql_query); } if (empty($row)) { if ($table == '*') { if ($db == '*') { $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;'; } elseif ($table == '*') { $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;'; } $res = PMA_DBI_query($sql_query); while ($row1 = PMA_DBI_fetch_row($res)) { if (substr($row1[0], 0, 4) == 'max_') { $row[$row1[0]] = 0; } else { $row[$row1[0]] = 'N'; } } PMA_DBI_free_result($res); } else { $row = array('Table_priv' => ''); } } if (isset($row['Table_priv'])) { $row1 = PMA_DBI_fetch_single_row( 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';', 'ASSOC', $GLOBALS['userlink'] ); // note: in MySQL 5.0.3 we get "Create View', 'Show view'; // the View for Create is spelled with uppercase V // the view for Show is spelled with lowercase v // and there is a space between the words $av_grants = explode( '\',\'', substr( $row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3 ) ); unset($row1); $users_grants = explode(',', $row['Table_priv']); foreach ($av_grants as $current_grant) { $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N'; } unset($row['Table_priv'], $current_grant, $av_grants, $users_grants); // get collumns $res = PMA_DBI_try_query( 'SHOW COLUMNS FROM ' . PMA_backquote(PMA_unescape_mysql_wildcards($db)) . '.' . PMA_backquote($table) . ';' ); $columns = array(); if ($res) { while ($row1 = PMA_DBI_fetch_row($res)) { $columns[$row1[0]] = array( 'Select' => false, 'Insert' => false, 'Update' => false, 'References' => false ); } PMA_DBI_free_result($res); } unset($res, $row1); } // t a b l e - s p e c i f i c p r i v i l e g e s if (! empty($columns)) { $res = PMA_DBI_query( 'SELECT `Column_name`, `Column_priv`' .' FROM `mysql`.`columns_priv`' .' WHERE `User`' .' = \'' . PMA_sqlAddSlashes($username) . "'" .' AND `Host`' .' = \'' . PMA_sqlAddSlashes($hostname) . "'" .' AND `Db`' .' = \'' . PMA_sqlAddSlashes(PMA_unescape_mysql_wildcards($db)) . "'" .' AND `Table_name`' .' = \'' . PMA_sqlAddSlashes($table) . '\';' ); while ($row1 = PMA_DBI_fetch_row($res)) { $row1[1] = explode(',', $row1[1]); foreach ($row1[1] as $current) { $columns[$row1[0]][$current] = true; } } PMA_DBI_free_result($res); unset($res, $row1, $current); echo '<input type="hidden" name="grant_count" value="' . count($row) . '" />' . "\n" . '<input type="hidden" name="column_count" value="' . count($columns) . '" />' . "\n" . '<fieldset id="fieldset_user_priv">' . "\n" . ' <legend>' . __('Table-specific privileges') . PMA_showHint(__('Note: MySQL privilege names are expressed in English')) . '</legend>' . "\n"; // privs that are attached to a specific column PMA_displayColumnPrivs( $columns, $row, 'Select_priv', 'SELECT', 'select', __('Allows reading data.'), 'Select' ); PMA_displayColumnPrivs( $columns, $row, 'Insert_priv', 'INSERT', 'insert', __('Allows inserting and replacing data.'), 'Insert' ); PMA_displayColumnPrivs( $columns, $row, 'Update_priv', 'UPDATE', 'update', __('Allows changing data.'), 'Update' ); PMA_displayColumnPrivs( $columns, $row, 'References_priv', 'REFERENCES', 'references', __('Has no effect in this MySQL version.'), 'References' ); // privs that are not attached to a specific column echo ' <div class="item">' . "\n"; foreach ($row as $current_grant => $current_grant_value) { $grant_type = substr($current_grant, 0, (strlen($current_grant) - 5)); if (in_array($grant_type, array('Select', 'Insert', 'Update', 'References'))) { continue; } // make a substitution to match the messages variables; // also we must substitute the grant we get, because we can't generate // a form variable containing blanks (those would get changed to // an underscore when receiving the POST) if ($current_grant == 'Create View_priv') { $tmp_current_grant = 'CreateView_priv'; $current_grant = 'Create_view_priv'; } elseif ($current_grant == 'Show view_priv') { $tmp_current_grant = 'ShowView_priv'; $current_grant = 'Show_view_priv'; } else { $tmp_current_grant = $current_grant; } echo ' <div class="item">' . "\n" . ' <input type="checkbox"' . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"') . ' name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="'; echo (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl']) . '"/>' . "\n"; echo ' <label for="checkbox_' . $current_grant . '"><code><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></code></label>' . "\n" . ' </div>' . "\n"; } // end foreach () echo ' </div>' . "\n"; // for Safari 2.0.2 echo ' <div class="clearfloat"></div>' . "\n"; } else { // g l o b a l o r d b - s p e c i f i c // $privTable_names = array(0 => __('Data'), 1 => __('Structure'), 2 => __('Administration')); // d a t a $privTable[0] = array( array('Select', 'SELECT', __('Allows reading data.')), array('Insert', 'INSERT', __('Allows inserting and replacing data.')), array('Update', 'UPDATE', __('Allows changing data.')), array('Delete', 'DELETE', __('Allows deleting data.')) ); if ($db == '*') { $privTable[0][] = array('File', 'FILE', __('Allows importing data from and exporting data into files.')); } // s t r u c t u r e $privTable[1] = array( array('Create', 'CREATE', ($table == '*' ? __('Allows creating new databases and tables.') : __('Allows creating new tables.'))), array('Alter', 'ALTER', __('Allows altering the structure of existing tables.')), array('Index', 'INDEX', __('Allows creating and dropping indexes.')), array('Drop', 'DROP', ($table == '*' ? __('Allows dropping databases and tables.') : __('Allows dropping tables.'))), array('Create_tmp_table', 'CREATE TEMPORARY TABLES', __('Allows creating temporary tables.')), array('Show_view', 'SHOW VIEW', __('Allows performing SHOW CREATE VIEW queries.')), array('Create_routine', 'CREATE ROUTINE', __('Allows creating stored routines.')), array('Alter_routine', 'ALTER ROUTINE', __('Allows altering and dropping stored routines.')), array('Execute', 'EXECUTE', __('Allows executing stored routines.')), ); // this one is for a db-specific priv: Create_view_priv if (isset($row['Create_view_priv'])) { $privTable[1][] = array('Create_view', 'CREATE VIEW', __('Allows creating new views.')); } // this one is for a table-specific priv: Create View_priv if (isset($row['Create View_priv'])) { $privTable[1][] = array('Create View', 'CREATE VIEW', __('Allows creating new views.')); } if (isset($row['Event_priv'])) { // MySQL 5.1.6 $privTable[1][] = array('Event', 'EVENT', __('Allows to set up events for the event scheduler')); $privTable[1][] = array('Trigger', 'TRIGGER', __('Allows creating and dropping triggers')); } // a d m i n i s t r a t i o n $privTable[2] = array( array('Grant', 'GRANT', __('Allows adding users and privileges without reloading the privilege tables.')), ); if ($db == '*') { $privTable[2][] = array('Super', 'SUPER', __('Allows connecting, even if maximum number of connections is reached; required for most administrative operations like setting global variables or killing threads of other users.')); $privTable[2][] = array('Process', 'PROCESS', __('Allows viewing processes of all users')); $privTable[2][] = array('Reload', 'RELOAD', __('Allows reloading server settings and flushing the server\'s caches.')); $privTable[2][] = array('Shutdown', 'SHUTDOWN', __('Allows shutting down the server.')); $privTable[2][] = array('Show_db', 'SHOW DATABASES', __('Gives access to the complete list of databases.')); } $privTable[2][] = array('Lock_tables', 'LOCK TABLES', __('Allows locking tables for the current thread.')); $privTable[2][] = array('References', 'REFERENCES', __('Has no effect in this MySQL version.')); if ($db == '*') { $privTable[2][] = array('Repl_client', 'REPLICATION CLIENT', __('Allows the user to ask where the slaves / masters are.')); $privTable[2][] = array('Repl_slave', 'REPLICATION SLAVE', __('Needed for the replication slaves.')); $privTable[2][] = array('Create_user', 'CREATE USER', __('Allows creating, dropping and renaming user accounts.')); } echo '<input type="hidden" name="grant_count" value="' . (count($privTable[0]) + count($privTable[1]) + count($privTable[2]) - (isset($row['Grant_priv']) ? 1 : 0)) . '" />' . "\n" . '<fieldset id="fieldset_user_global_rights">' . "\n" . ' <legend>' . "\n" . ' ' . ($db == '*' ? __('Global privileges') : ($table == '*' ? __('Database-specific privileges') : __('Table-specific privileges'))) . "\n" . ' (<a href="server_privileges.php?' . $GLOBALS['url_query'] . '&checkall=1" onclick="setCheckboxes(\'addUsersForm_' . $random_n . '\', true); return false;">' . __('Check All') . '</a> /' . "\n" . ' <a href="server_privileges.php?' . $GLOBALS['url_query'] . '" onclick="setCheckboxes(\'addUsersForm_' . $random_n . '\', false); return false;">' . __('Uncheck All') . '</a>)' . "\n" . ' </legend>' . "\n" . ' <p><small><i>' . __('Note: MySQL privilege names are expressed in English') . '</i></small></p>' . "\n"; // Output the Global privilege tables with checkboxes foreach ($privTable as $i => $table) { echo ' <fieldset>' . "\n" . ' <legend>' . __($privTable_names[$i]) . '</legend>' . "\n"; foreach ($table as $priv) { echo ' <div class="item">' . "\n" . ' <input type="checkbox"' . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0] . '_priv"' . ' value="Y" title="' . $priv[2] . '"' . ((! empty($GLOBALS['checkall']) || $row[$priv[0] . '_priv'] == 'Y') ? ' checked="checked"' : '') . '/>' . "\n" . ' <label for="checkbox_' . $priv[0] . '_priv"><code><dfn title="' . $priv[2] . '">' . $priv[1] . '</dfn></code></label>' . "\n" . ' </div>' . "\n"; } echo ' </fieldset>' . "\n"; } // The "Resource limits" box is not displayed for db-specific privs if ($db == '*') { echo ' <fieldset>' . "\n" . ' <legend>' . __('Resource limits') . '</legend>' . "\n" . ' <p><small><i>' . __('Note: Setting these options to 0 (zero) removes the limit.') . '</i></small></p>' . "\n" . ' <div class="item">' . "\n" . ' <label for="text_max_questions"><code><dfn title="' . __('Limits the number of queries the user may send to the server per hour.') . '">MAX QUERIES PER HOUR</dfn></code></label>' . "\n" . ' <input type="text" name="max_questions" id="text_max_questions" value="' . $row['max_questions'] . '" size="11" maxlength="11" title="' . __('Limits the number of queries the user may send to the server per hour.') . '" />' . "\n" . ' </div>' . "\n" . ' <div class="item">' . "\n" . ' <label for="text_max_updates"><code><dfn title="' . __('Limits the number of commands that change any table or database the user may execute per hour.') . '">MAX UPDATES PER HOUR</dfn></code></label>' . "\n" . ' <input type="text" name="max_updates" id="text_max_updates" value="' . $row['max_updates'] . '" size="11" maxlength="11" title="' . __('Limits the number of commands that change any table or database the user may execute per hour.') . '" />' . "\n" . ' </div>' . "\n" . ' <div class="item">' . "\n" . ' <label for="text_max_connections"><code><dfn title="' . __('Limits the number of new connections the user may open per hour.') . '">MAX CONNECTIONS PER HOUR</dfn></code></label>' . "\n" . ' <input type="text" name="max_connections" id="text_max_connections" value="' . $row['max_connections'] . '" size="11" maxlength="11" title="' . __('Limits the number of new connections the user may open per hour.') . '" />' . "\n" . ' </div>' . "\n" . ' <div class="item">' . "\n" . ' <label for="text_max_user_connections"><code><dfn title="' . __('Limits the number of simultaneous connections the user may have.') . '">MAX USER_CONNECTIONS</dfn></code></label>' . "\n" . ' <input type="text" name="max_user_connections" id="text_max_user_connections" value="' . $row['max_user_connections'] . '" size="11" maxlength="11" title="' . __('Limits the number of simultaneous connections the user may have.') . '" />' . "\n" . ' </div>' . "\n" . ' </fieldset>' . "\n"; } // for Safari 2.0.2 echo ' <div class="clearfloat"></div>' . "\n"; } echo '</fieldset>' . "\n"; if ($submit) { echo '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">' . "\n" . ' <input type="submit" name="update_privs" value="' . __('Go') . '" />' . "\n" . '</fieldset>' . "\n"; } } // end of the 'PMA_displayPrivTable()' function
/** * renames table * * @param string new table name * @param string new database name * @return boolean success */ function rename($new_name, $new_db = null) { if (null !== $new_db && $new_db !== $this->getDbName()) { // Ensure the target is valid if (!$GLOBALS['PMA_List_Database']->exists($new_db)) { $this->errors[] = $GLOBALS['strInvalidDatabase'] . ': ' . $new_db; return false; } } else { $new_db = $this->getDbName(); } $new_table = new PMA_Table($new_name, $new_db); if ($this->getFullName() === $new_table->getFullName()) { return true; } if (!PMA_Table::isValidName($new_name)) { $this->errors[] = $GLOBALS['strInvalidTableName'] . ': ' . $new_table->getFullName(); return false; } $GLOBALS['sql_query'] = ' RENAME TABLE ' . $this->getFullName(true) . ' TO ' . $new_table->getFullName(true) . ';'; if (!PMA_DBI_query($GLOBALS['sql_query'])) { $this->errors[] = sprintf($GLOBALS['strErrorRenamingTable'], $this->getFullName(), $new_table->getFullName()); return false; } $old_name = $this->getName(); $old_db = $this->getDbName(); $this->setName($new_name); $this->setDbName($new_db); /** * @todo move into extra function PMA_Relation::renameTable($new_name, $old_name, $new_db, $old_db) */ // garvin: Move old entries from comments to new table require_once './libraries/relation.lib.php'; $GLOBALS['cfgRelation'] = PMA_getRelationsParam(); if ($GLOBALS['cfgRelation']['commwork']) { $remove_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_cu($remove_query); unset($remove_query); } if ($GLOBALS['cfgRelation']['displaywork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_cu($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['relwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET `foreign_db` = \'' . PMA_sqlAddslashes($new_db) . '\', `foreign_table` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `foreign_db` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `foreign_table` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_cu($table_query); $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET `master_db` = \'' . PMA_sqlAddslashes($new_db) . '\', `master_table` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `master_db` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `master_table` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_cu($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['pdfwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_cu($table_query); unset($table_query); } if ($GLOBALS['cfgRelation']['designerwork']) { $table_query = ' UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . ' SET `db_name` = \'' . PMA_sqlAddslashes($new_db) . '\', `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\' WHERE `db_name` = \'' . PMA_sqlAddslashes($old_db) . '\' AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\''; PMA_query_as_cu($table_query); unset($table_query); } $this->messages[] = sprintf($GLOBALS['strRenameTableOK'], htmlspecialchars($old_name), htmlspecialchars($new_name)); return true; }
" colspan="2"> <?php echo $strReferentialIntegrity; ?> <br /> <?php echo "\n"; foreach ($foreign as $master => $arr) { $join_query = 'SELECT ' . PMA_backquote($table) . '.* FROM ' . PMA_backquote($table) . ' LEFT JOIN ' . PMA_backquote($arr['foreign_table']); if ($arr['foreign_table'] == $table) { $foreign_table = $table . '1'; $join_query .= ' AS ' . PMA_backquote($foreign_table); } else { $foreign_table = $arr['foreign_table']; } $join_query .= ' ON ' . PMA_backquote($table) . '.' . PMA_backquote($master) . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field']) . ' WHERE ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field']) . ' IS NULL AND ' . PMA_backquote($table) . '.' . PMA_backquote($master) . ' IS NOT NULL'; echo ' ' . '<a href="sql.php?' . $url_query . '&sql_query=' . urlencode($join_query) . '">' . $master . ' -> ' . $arr['foreign_table'] . '.' . $arr['foreign_field'] . '</a><br />' . "\n"; unset($foreign_table); unset($join_query); } // end while ?> </td> </tr> <?php } // end if ($result) echo "\n"; } // end if (!empty($cfg['Server']['relation'])) ?>
// uses SHOW CREATE $definition = 'DROP ' . $routine['ROUTINE_TYPE'] . ' ' . PMA_backquote($routine['SPECIFIC_NAME']) . $delimiter . "\n" . PMA_DBI_get_definition($db, $routine['ROUTINE_TYPE'], $routine['SPECIFIC_NAME']) . "\n"; //if ($routine['ROUTINE_TYPE'] == 'PROCEDURE') { // $sqlUseProc = 'CALL ' . $routine['SPECIFIC_NAME'] . '()'; //} else { // $sqlUseProc = 'SELECT ' . $routine['SPECIFIC_NAME'] . '()'; /* this won't get us far: to really use the function i'd need to know how many parameters the function needs and then create something to ask for them. As i don't see this directly in the table i am afraid that requires parsing the ROUTINE_DEFINITION and i don't really need that now so i simply don't offer a method for running the function*/ //} if ($routine['ROUTINE_TYPE'] == 'PROCEDURE') { $sqlDropProc = 'DROP PROCEDURE ' . PMA_backquote($routine['SPECIFIC_NAME']); } else { $sqlDropProc = 'DROP FUNCTION ' . PMA_backquote($routine['SPECIFIC_NAME']); } echo sprintf('<tr class="%s"> <td><strong>%s</strong></td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> </tr>', $ct % 2 == 0 ? 'even' : 'odd', $routine['ROUTINE_NAME'], !empty($definition) ? PMA_linkOrButton('db_sql.php?' . $url_query . '&sql_query=' . urlencode($definition) . '&show_query=1&db_query_force=1&delimiter=' . urlencode($delimiter), $titles['Structure']) : ' ', '<a href="sql.php?' . $url_query . '&sql_query=' . urlencode($sqlDropProc) . '" onclick="return confirmLink(this, \'' . PMA_jsFormat($sqlDropProc, false) . '\')">' . $titles['Drop'] . '</a>', $routine['ROUTINE_TYPE'], $routine['DTD_IDENTIFIER']); $ct++; } echo '</table>'; echo '</fieldset>' . "\n"; echo '</div>' . "\n"; }
/** * Deletes a bookmark * * @uses PMA_backquote() * @uses PMA_sqlAddslashes() * @uses PMA_DBI_try_query() * @uses PMA_Bookmark_getParams() * @global resource the controluser db connection handle * * @param string the current database name * @param integer the id of the bookmark to get * * @access public */ function PMA_Bookmark_delete($db, $id) { global $controllink; $cfgBookmark = PMA_Bookmark_getParams(); if (empty($cfgBookmark)) { return false; } $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) . ' WHERE (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' . ' OR user = \'\')' . ' AND id = ' . $id; return PMA_DBI_try_query($query, $controllink); }
// Not a valid db name -> back to the welcome page if (strlen($db)) { $is_db = PMA_DBI_select_db($db); } if (! strlen($db) || !$is_db) { PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'main.php?' . PMA_generate_common_url('', '', '&') . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1'); exit; } } // end if (ensures db exists) /** * Changes database charset if requested by the user */ if (isset($submitcollation) && !empty($db_collation)) { list($db_charset) = explode('_', $db_collation); $sql_query = 'ALTER DATABASE ' . PMA_backquote($db) . ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation); $result = PMA_DBI_query($sql_query); $message = PMA_Message::success(); unset($db_charset, $db_collation); } $GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/header.inc.php'; /** * Set parameters for links */ $url_query = PMA_generate_common_url($db); ?>
?> </select> <input type="submit" name="show_versions_submit" value="<?php echo $strTrackingShowVersions; ?> " /> </form> <?php } ?> <br /> <?php /* * List versions of current table */ $sql_query = " SELECT * FROM " . PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) . "." . PMA_backquote($GLOBALS['cfg']['Server']['tracking']) . " WHERE " . PMA_backquote('db_name') . " = '" . PMA_sqlAddslashes($_REQUEST['db']) . "' " . " AND " . PMA_backquote('table_name') . " = '" . PMA_sqlAddslashes($_REQUEST['table']) . "' " . " ORDER BY " . PMA_backquote('version') . " DESC "; $sql_result = PMA_query_as_controluser($sql_query); $last_version = 0; $maxversion = PMA_DBI_fetch_array($sql_result); $last_version = $maxversion['version']; if ($last_version > 0) { ?> <table id="versions" class="data"> <thead> <tr> <th><?php echo $strDatabase; ?> </th> <th><?php echo $strTable;
/** * Builds the SQL search query * * @param string $table the table name * @param string $field restrict the search to this field * @param string $search_str the string to search * @param integer $search_option type of search * (1 -> 1 word at least, 2 -> all words, * 3 -> exact string, 4 -> regexp) * * @return array 3 SQL querys (for count, display and delete results) * * @todo can we make use of fulltextsearch IN BOOLEAN MODE for this? * PMA_backquote * PMA_DBI_free_result * PMA_DBI_fetch_assoc * $GLOBALS['db'] * explode * count * strlen */ function PMA_getSearchSqls($table, $field, $search_str, $search_option) { // Statement types $sqlstr_select = 'SELECT'; $sqlstr_delete = 'DELETE'; // Fields to select $tblfields = PMA_DBI_get_columns($GLOBALS['db'], $table); // Table to use $sqlstr_from = ' FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($table); $search_words = $search_option > 2 ? array($search_str) : explode(' ', $search_str); $like_or_regex = $search_option == 4 ? 'REGEXP' : 'LIKE'; $automatic_wildcard = $search_option < 3 ? '%' : ''; $fieldslikevalues = array(); foreach ($search_words as $search_word) { // Eliminates empty values if (strlen($search_word) === 0) { continue; } $thefieldlikevalue = array(); foreach ($tblfields as $tblfield) { if (!isset($field) || strlen($field) == 0 || $tblfield['Field'] == $field) { // Drizzle has no CONVERT and all text columns are UTF-8 if (PMA_DRIZZLE) { $thefieldlikevalue[] = PMA_backquote($tblfield['Field']) . ' ' . $like_or_regex . ' ' . "'" . $automatic_wildcard . $search_word . $automatic_wildcard . "'"; } else { $thefieldlikevalue[] = 'CONVERT(' . PMA_backquote($tblfield['Field']) . ' USING utf8)' . ' ' . $like_or_regex . ' ' . "'" . $automatic_wildcard . $search_word . $automatic_wildcard . "'"; } } } // end for if (count($thefieldlikevalue) > 0) { $fieldslikevalues[] = implode(' OR ', $thefieldlikevalue); } } // end for $implode_str = $search_option == 1 ? ' OR ' : ' AND '; if (empty($fieldslikevalues)) { // this could happen when the "inside field" does not exist // in any selected tables $sqlstr_where = ' WHERE FALSE'; } else { $sqlstr_where = ' WHERE (' . implode(') ' . $implode_str . ' (', $fieldslikevalues) . ')'; } unset($fieldslikevalues); // Builds complete queries $sql['select_fields'] = $sqlstr_select . ' * ' . $sqlstr_from . $sqlstr_where; // here, I think we need to still use the COUNT clause, even for // VIEWs, anyway we have a WHERE clause that should limit results $sql['select_count'] = $sqlstr_select . ' COUNT(*) AS `count`' . $sqlstr_from . $sqlstr_where; $sql['delete'] = $sqlstr_delete . $sqlstr_from . $sqlstr_where; return $sql; }