Пример #1
0
/**
 * Gets the list of bookmarks defined for the current database
 *
 * @param   string   the current database name
 * @param   array    the bookmark parameters for the current user
 *
 * @return  mixed    the bookmarks list if defined, false else
 *
 * @access  public
 */
function PMA_listBookmarks($db, $cfgBookmark)
{
    $query = 'SELECT label, id FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' . '      OR user = \'\')';
    if (isset($GLOBALS['dbh'])) {
        $result = PMA_mysql_query($query, $GLOBALS['dbh']);
    } else {
        $result = PMA_mysql_query($query);
    }
    // There is some bookmarks -> store them
    if ($result > 0 && mysql_num_rows($result) > 0) {
        $flag = 1;
        while ($row = PMA_mysql_fetch_row($result)) {
            $bookmark_list[$flag . ' - ' . $row[0]] = $row[1];
            $flag++;
        }
        // end while
        return $bookmark_list;
    } else {
        return FALSE;
    }
}
Пример #2
0
 /**
  * Ouputs the PDF document to a file
  *
  * @global  object   The current PDF document
  * @global  string   The current database name
  * @global  integer  The current page number (from the
  *                   $cfg['Servers'][$i]['table_coords'] table)
  *
  * @access  private
  *
  * @see     PMA_PDF
  */
 function PMA_RT_showRt()
 {
     global $pdf, $db, $pdf_page_number, $cfgRelation;
     $pdf->SetFontSize(14);
     $pdf->SetLineWidth(0.2);
     $pdf->SetDisplayMode('fullpage');
     //  Get the name of this pdfpage to use as filename (Mike Beck)
     $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE page_nr = ' . $pdf_page_number;
     $_name_rs = PMA_query_as_cu($_name_sql);
     if ($_name_rs) {
         $_name_row = PMA_mysql_fetch_row($_name_rs);
         $filename = $_name_row[0] . '.pdf';
     }
     // i don't know if there is a chance for this to happen, but rather be on the safe side:
     if (empty($filename)) {
         $filename = $pdf_page_number . '.pdf';
     }
     $pdf->Output($db . '_' . $filename, TRUE);
     //$pdf->Output('', TRUE);
 }
Пример #3
0
 * Sends the queries and buffers the results
 */
if (PMA_MYSQL_INT_VERSION >= 40003) {
    $res = @PMA_mysql_query('SHOW SESSION VARIABLES;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW SESSION VARIABLES;');
    while ($row = PMA_mysql_fetch_row($res)) {
        $serverVars[$row[0]] = $row[1];
    }
    @mysql_free_result($res);
    $res = @PMA_mysql_query('SHOW GLOBAL VARIABLES;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW GLOBAL VARIABLES;');
    while ($row = PMA_mysql_fetch_row($res)) {
        $serverVarsGlobal[$row[0]] = $row[1];
    }
    @mysql_free_result($res);
} else {
    $res = @PMA_mysql_query('SHOW VARIABLES;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW VARIABLES;');
    while ($row = PMA_mysql_fetch_row($res)) {
        $serverVars[$row[0]] = $row[1];
    }
    @mysql_free_result($res);
}
unset($res);
unset($row);
/**
 * Displays the page
 */
?>
<table border="0">
    <tr>
        <th>&nbsp;<?php 
echo $strVar;
?>
Пример #4
0
                        </tr>
<?php 
        }
    }
    unset($useBgcolorOne);
    ?>
                    </table>
                </td>
            </tr>
        </table>
    </li>
<?php 
}
$res = PMA_mysql_query('SHOW VARIABLES LIKE "have_innodb";', $userlink);
if ($res) {
    $row = PMA_mysql_fetch_row($res);
    if (!empty($row[1]) && $row[1] == 'YES') {
        ?>
    <br />
    <li>
        <!-- InnoDB Status -->
        <a href="./server_status.php?<?php 
        echo $url_query;
        ?>
&amp;innodbstatus=1">
            <b><?php 
        echo $strInnodbStat;
        ?>
</b>
        </a>
    </li>
Пример #5
0
 $local_query = 'SHOW OPEN TABLES FROM ' . PMA_backquote($db);
 $db_info_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0);
 // Blending out tables in use
 if ($db_info_result != FALSE && mysql_num_rows($db_info_result) > 0) {
     while ($tmp = PMA_mysql_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;
         }
     }
     mysql_free_result($db_info_result);
     if (isset($sot_cache)) {
         $local_query = 'SHOW TABLES FROM ' . PMA_backquote($db);
         $db_info_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0);
         if ($db_info_result != FALSE && mysql_num_rows($db_info_result) > 0) {
             while ($tmp = PMA_mysql_fetch_row($db_info_result)) {
                 if (!isset($sot_cache[$tmp[0]])) {
                     $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\'';
                     $sts_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0);
                     $sts_tmp = PMA_mysql_fetch_array($sts_result);
                     $tables[] = $sts_tmp;
                 } else {
                     // table in use
                     $tables[] = array('Name' => $tmp[0]);
                 }
             }
             mysql_free_result($db_info_result);
             $sot_ready = TRUE;
         }
     }
 }
Пример #6
0
 function PMA_getDbCollation($db)
 {
     global $userlink;
     if (PMA_MYSQL_INT_VERSION >= 40101) {
         // MySQL 4.1.0 does not support seperate charset settings
         // for databases.
         $sql_query = 'SHOW CREATE DATABASE ' . PMA_backquote($db) . ';';
         $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
         $row = PMA_mysql_fetch_row($res);
         mysql_free_result($res);
         $tokenized = explode(' ', $row[1]);
         unset($row, $res, $sql_query);
         for ($i = 1; $i + 3 < count($tokenized); $i++) {
             if ($tokenized[$i] == 'DEFAULT' && $tokenized[$i + 1] == 'CHARACTER' && $tokenized[$i + 2] == 'SET') {
                 // We've found the character set!
                 if (isset($tokenized[$i + 5]) && $tokenized[$i + 4] == 'COLLATE') {
                     return $tokenized[$i + 5];
                     // We found the collation!
                 } else {
                     // We did not find the collation, so let's return the
                     // default collation for the charset we've found.
                     return $GLOBALS['mysql_default_collations'][$tokenized[$i + 3]];
                 }
             }
         }
     }
     return '';
 }
Пример #7
0
/**
 * Outputs the content of a table in CSV format
 *
 * @param   string      the database name
 * @param   string      the table name
 * @param   string      the end of line sequence
 * @param   string      the url to go back in case of error
 * @param   string      SQL query for obtaining data
 *
 * @return  bool        Whether it suceeded
 *
 * @access  public
 */
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
    global $what;
    global $add_character;
    global $separator;
    global $enclosed;
    global $escaped;
    // Gets the data from the database
    $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url);
    $fields_cnt = mysql_num_fields($result);
    // If required, get fields name at the first line
    if (isset($GLOBALS['showcsvnames']) && $GLOBALS['showcsvnames'] == 'yes') {
        $schema_insert = '';
        for ($i = 0; $i < $fields_cnt; $i++) {
            if ($enclosed == '') {
                $schema_insert .= stripslashes(mysql_field_name($result, $i));
            } else {
                $schema_insert .= $enclosed . str_replace($enclosed, $escaped . $enclosed, stripslashes(mysql_field_name($result, $i))) . $enclosed;
            }
            $schema_insert .= $separator;
        }
        // end for
        $schema_insert = trim(substr($schema_insert, 0, -1));
        if (!PMA_exportOutputHandler($schema_insert . $add_character)) {
            return FALSE;
        }
    }
    // end if
    // Format the data
    while ($row = PMA_mysql_fetch_row($result)) {
        $schema_insert = '';
        for ($j = 0; $j < $fields_cnt; $j++) {
            if (!isset($row[$j])) {
                $schema_insert .= $GLOBALS[$what . '_replace_null'];
            } else {
                if ($row[$j] == '0' || $row[$j] != '') {
                    $row[$j] = stripslashes($row[$j]);
                    // loic1 : always enclose fields
                    if ($what == 'excel') {
                        $row[$j] = ereg_replace("\r(\n)?", "\n", $row[$j]);
                    }
                    if ($enclosed == '') {
                        $schema_insert .= $row[$j];
                    } else {
                        $schema_insert .= $enclosed . str_replace($enclosed, $escaped . $enclosed, $row[$j]) . $enclosed;
                    }
                } else {
                    $schema_insert .= '';
                }
            }
            if ($j < $fields_cnt - 1) {
                $schema_insert .= $separator;
            }
        }
        // end for
        if (!PMA_exportOutputHandler($schema_insert . $add_character)) {
            return FALSE;
        }
    }
    // end while
    mysql_free_result($result);
    return TRUE;
}
Пример #8
0
/**
 * Displays the fields used by the "new user" form as well as the
 * "change login information / copy user" form.
 *
 * @param   string     are we creating a new user or are we just changing one?
 *                     (allowed values: 'new', 'change')
 * @param   int        the indenting level of the code
 *
 * @global  array      the phpMyAdmin configuration
 * @global  ressource  the database connection
 *
 * @return  void
 */
function PMA_displayLoginInformationFields($mode = 'new', $indent = 0)
{
    global $cfg, $userlink;
    $spaces = '';
    for ($i = 0; $i < $indent; $i++) {
        $spaces .= '    ';
    }
    echo $spaces . '<tr>' . "\n" . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . '        <label for="select_pred_username">' . "\n" . $spaces . '            ' . $GLOBALS['strUserName'] . ':' . "\n" . $spaces . '        </label>' . "\n" . $spaces . '    </td>' . "\n" . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . '        <select name="pred_username" id="select_pred_username" title="' . $GLOBALS['strUserName'] . '"' . "\n" . $spaces . '            onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">' . "\n" . $spaces . '            <option value="any"' . (isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any' ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyUser'] . '</option>' . "\n" . $spaces . '            <option value="userdefined"' . (!isset($GLOBALS['pred_username']) || $GLOBALS['pred_username'] == 'userdefined' ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n" . $spaces . '        </select>' . "\n" . $spaces . '    </td>' . "\n" . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . '        <input type="text" class="textfield" name="username" class="textfield" title="' . $GLOBALS['strUserName'] . '"' . (empty($GLOBALS['username']) ? '' : ' value="' . (isset($GLOBALS['new_username']) ? $GLOBALS['new_username'] : $GLOBALS['username']) . '"') . ' onchange="pred_username.value = \'userdefined\';" />' . "\n" . $spaces . '    </td>' . "\n" . $spaces . '</tr>' . "\n" . $spaces . '<tr>' . "\n" . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . '        <label for="select_pred_hostname">' . "\n" . $spaces . '            ' . $GLOBALS['strHost'] . ':' . "\n" . $spaces . '        </label>' . "\n" . $spaces . '    </td>' . "\n" . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . '        <select name="pred_hostname" id="select_pred_hostname" title="' . $GLOBALS['strHost'] . '"' . "\n";
    $res = PMA_mysql_query('SELECT USER();', $userlink);
    $row = @PMA_mysql_fetch_row($res);
    @mysql_free_result($res);
    unset($res);
    if (!empty($row[0])) {
        $thishost = str_replace("'", '', substr($row[0], strrpos($row[0], '@') + 1));
        if ($thishost == 'localhost' || $thishost == '127.0.0.1') {
            unset($thishost);
        }
    }
    echo $spaces . '            onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } ' . (empty($thishost) ? '' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ') . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
    unset($row);
    echo $spaces . '            <option value="any"' . (isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any' ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyHost'] . '</option>' . "\n" . $spaces . '            <option value="localhost"' . (isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost' ? ' selected="selected"' : '') . '>' . $GLOBALS['strLocalhost'] . '</option>' . "\n";
    if (!empty($thishost)) {
        echo $spaces . '            <option value="thishost"' . (isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost' ? ' selected="selected"' : '') . '>' . $GLOBALS['strThisHost'] . '</option>' . "\n";
    }
    unset($thishost);
    echo $spaces . '            <option value="hosttable"' . (isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable' ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseHostTable'] . '</option>' . "\n" . $spaces . '            <option value="userdefined"' . (isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined' ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n" . $spaces . '        </select>' . "\n" . $spaces . '    </td>' . "\n" . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . '        <input type="text" class="textfield" name="hostname" value="' . (isset($GLOBALS['hostname']) ? $GLOBALS['hostname'] : '') . '" class="textfield" title="' . $GLOBALS['strHost'] . '" onchange="pred_hostname.value = \'userdefined\';" />' . "\n" . $spaces . '    </td>' . "\n" . $spaces . '</tr>' . "\n" . $spaces . '<tr>' . "\n" . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . '        <label for="select_pred_password">' . "\n" . $spaces . '            ' . $GLOBALS['strPassword'] . ':' . "\n" . $spaces . '        </label>' . "\n" . $spaces . '    </td>' . "\n" . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . '        <select name="pred_password" id="select_pred_password" title="' . $GLOBALS['strPassword'] . '"' . "\n" . $spaces . '            onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">' . "\n" . ($mode == 'change' ? $spaces . '            <option value="keep" selected="selected">' . $GLOBALS['strKeepPass'] . '</option>' . "\n" : '') . $spaces . '            <option value="none">' . $GLOBALS['strNoPassword'] . '</option>' . "\n" . $spaces . '            <option value="userdefined"' . ($mode == 'change' ? '' : ' selected="selected"') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n" . $spaces . '        </select>' . "\n" . $spaces . '    </td>' . "\n" . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . '        <input type="password" name="pma_pw" class="textfield" title="' . $GLOBALS['strPassword'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n" . $spaces . '    </td>' . "\n" . $spaces . '</tr>' . "\n" . $spaces . '<tr>' . "\n" . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . '        <label for="text_pma_pw2">' . "\n" . $spaces . '            ' . $GLOBALS['strReType'] . ':' . "\n" . $spaces . '        </label>' . "\n" . $spaces . '    </td>' . "\n" . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">&nbsp;</td>' . "\n" . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . '        <input type="password" name="pma_pw2" id="text_pma_pw2" class="textfield" title="' . $GLOBALS['strReType'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n" . $spaces . '    </td>' . "\n" . $spaces . '</tr>' . "\n";
}
Пример #9
0
         // We don't want more than one asterisk inside our 'only_db'.
         continue;
     }
     if ($is_show_dbs && ereg('(^|[^\\])(_|%)', $dblist[$i])) {
         $local_query = 'SHOW DATABASES LIKE \'' . $dblist[$i] . '\'';
         $rs = PMA_mysql_query($local_query, $dbh);
         // "SHOW DATABASES" statement is disabled
         if ($i == 0 && (PMA_mysql_error() && mysql_errno() == 1045)) {
             $true_dblist[] = str_replace('\\_', '_', str_replace('\\%', '%', $dblist[$i]));
             $is_show_dbs = FALSE;
         }
         // Debug
         // else if (PMA_mysql_error()) {
         //    PMA_mysqlDie('', $local_query, FALSE);
         // }
         while ($row = @PMA_mysql_fetch_row($rs)) {
             $true_dblist[] = $row[0];
         }
         // end while
         if ($rs) {
             mysql_free_result($rs);
         }
     } else {
         $true_dblist[] = str_replace('\\_', '_', str_replace('\\%', '%', $dblist[$i]));
     }
     // end if... else...
 }
 // end for
 $dblist = $true_dblist;
 unset($true_dblist);
 $only_db_check = TRUE;
Пример #10
0
 *    PMA_MYSQL_INT_VERSION    (int)    - eg: 32339 instead of 3.23.39
 *    PMA_USR_OS               (string) - the plateform (os) of the user
 *    PMA_USR_BROWSER_AGENT    (string) - the browser of the user
 *    PMA_USR_BROWSER_VER      (double) - the version of this browser
 */
// MySQL Version
if (!defined('PMA_MYSQL_INT_VERSION') && isset($userlink)) {
    if (!empty($server)) {
        $result = PMA_mysql_query('SELECT VERSION() AS version');
        if ($result != FALSE && @mysql_num_rows($result) > 0) {
            $row = PMA_mysql_fetch_array($result);
            $match = explode('.', $row['version']);
        } else {
            $result = @PMA_mysql_query('SHOW VARIABLES LIKE \'version\'');
            if ($result != FALSE && @mysql_num_rows($result) > 0) {
                $row = PMA_mysql_fetch_row($result);
                $match = explode('.', $row[1]);
            }
        }
    }
    // end server id is defined case
    if (!isset($match) || !isset($match[0])) {
        $match[0] = 3;
    }
    if (!isset($match[1])) {
        $match[1] = 21;
    }
    if (!isset($match[2])) {
        $match[2] = 0;
    }
    if (!isset($row)) {
Пример #11
0
/**
 * Dispatches between the versions of 'getTableContent' to use depending
 * on the php version
 *
 * @param   string      the database name
 * @param   string      the table name
 * @param   string      the end of line sequence
 * @param   string      the url to go back in case of error
 * @param   string      SQL query for obtaining data
 *
 * @return  bool        Whether it suceeded
 *
 * @global  boolean  whether to use backquotes to allow the use of special
 *                   characters in database, table and fields names or not
 * @global  integer  the number of records
 * @global  integer  the current record position
 *
 * @access  public
 *
 * @see     PMA_getTableContentFast(), PMA_getTableContentOld()
 *
 * @author  staybyte
 */
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
    global $use_backquotes;
    global $rows_cnt;
    global $current_row;
    $formatted_table_name = isset($GLOBALS['use_backquotes']) ? PMA_backquote($table) : '\'' . $table . '\'';
    $head = $crlf . '#' . $crlf . '# ' . $GLOBALS['strDumpingData'] . ' ' . $formatted_table_name . $crlf . '#' . $crlf . $crlf;
    if (!PMA_exportOutputHandler($head)) {
        return FALSE;
    }
    $buffer = '';
    $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url);
    if ($result != FALSE) {
        $fields_cnt = mysql_num_fields($result);
        $rows_cnt = mysql_num_rows($result);
        // get the real types of the table's fields (in an array)
        // the key of the array is the backquoted field name
        $field_types = PMA_fieldTypes($db, $table, $use_backquotes);
        // analyze the query to get the true column names, not the aliases
        // (this fixes an undefined index, also if Complete inserts
        //  are used, we did not get the true column name in case of aliases)
        $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($sql_query));
        // Checks whether the field is an integer or not
        for ($j = 0; $j < $fields_cnt; $j++) {
            if (isset($analyzed_sql[0]['select_expr'][$j]['column'])) {
                $field_set[$j] = PMA_backquote($analyzed_sql[0]['select_expr'][$j]['column'], $use_backquotes);
            } else {
                $field_set[$j] = PMA_backquote(PMA_mysql_field_name($result, $j), $use_backquotes);
            }
            $type = $field_types[$field_set[$j]];
            if ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' || $type == 'bigint' || PMA_MYSQL_INT_VERSION < 40100 && $type == 'timestamp') {
                $field_num[$j] = TRUE;
            } else {
                $field_num[$j] = FALSE;
            }
            // blob
            if ($type == 'blob' || $type == 'mediumblob' || $type == 'longblob' || $type == 'tinyblob') {
                $field_blob[$j] = TRUE;
            } else {
                $field_blob[$j] = FALSE;
            }
        }
        // end for
        if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'update') {
            // update
            $schema_insert = 'UPDATE ' . PMA_backquote($table, $use_backquotes) . ' SET ';
            $fields_no = count($field_set);
        } else {
            // insert or replace
            if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'replace') {
                $sql_command = 'REPLACE';
            } else {
                $sql_command = 'INSERT';
            }
            // delayed inserts?
            if (isset($GLOBALS['delayed'])) {
                $insert_delayed = ' DELAYED';
            } else {
                $insert_delayed = '';
            }
            // Sets the scheme
            if (isset($GLOBALS['showcolumns'])) {
                $fields = implode(', ', $field_set);
                $schema_insert = $sql_command . $insert_delayed . ' INTO ' . PMA_backquote($table, $use_backquotes) . ' (' . $fields . ') VALUES (';
            } else {
                $schema_insert = $sql_command . $insert_delayed . ' INTO ' . PMA_backquote($table, $use_backquotes) . ' VALUES (';
            }
        }
        $search = array("", "\n", "\r", "");
        //\x08\\x09, not required
        $replace = array('\\0', '\\n', '\\r', '\\Z');
        $current_row = 0;
        while ($row = PMA_mysql_fetch_row($result)) {
            $current_row++;
            for ($j = 0; $j < $fields_cnt; $j++) {
                if (!isset($row[$j])) {
                    $values[] = 'NULL';
                } else {
                    if ($row[$j] == '0' || $row[$j] != '') {
                        // a number
                        if ($field_num[$j]) {
                            $values[] = $row[$j];
                            // a not empty blob
                        } else {
                            if ($field_blob[$j] && !empty($row[$j])) {
                                $values[] = '0x' . bin2hex($row[$j]);
                                // a string
                            } else {
                                $values[] = "'" . str_replace($search, $replace, PMA_sqlAddslashes($row[$j])) . "'";
                            }
                        }
                    } else {
                        $values[] = "''";
                    }
                }
                // end if
            }
            // end for
            // should we make update?
            if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'update') {
                $insert_line = $schema_insert;
                for ($i = 0; $i < $fields_no; $i++) {
                    if ($i > 0) {
                        $insert_line .= ', ';
                    }
                    $insert_line .= $field_set[$i] . ' = ' . $values[$i];
                }
            } else {
                // Extended inserts case
                if (isset($GLOBALS['extended_ins'])) {
                    if ($current_row == 1) {
                        $insert_line = $schema_insert . implode(', ', $values) . ')';
                    } else {
                        $insert_line = '(' . implode(', ', $values) . ')';
                    }
                } else {
                    $insert_line = $schema_insert . implode(', ', $values) . ')';
                }
            }
            unset($values);
            if (!PMA_exportOutputHandler($insert_line . (isset($GLOBALS['extended_ins']) && $current_row < $rows_cnt ? ',' : ';') . $crlf)) {
                return FALSE;
            }
        }
        // end while
    }
    // end if ($result != FALSE)
    mysql_free_result($result);
    return TRUE;
}
Пример #12
0
 // GRANTS...
 // Maybe we'll find a little CREATE priv there :)
 $local_query = 'SHOW GRANTS FOR ' . $mysql_cur_user_and_host;
 $rs_usr = PMA_mysql_query($local_query, $dbh);
 if (!$rs_usr) {
     // OK, now we'd have to guess the user's hostname, but we
     // only try out the 'username'@'%' case.
     $local_query = 'SHOW GRANTS FOR ' . $mysql_cur_user;
     $rs_usr = PMA_mysql_query($local_query, $dbh);
 }
 if ($rs_usr) {
     $re0 = '(^|(\\\\\\\\)+|[^\\])';
     // non-escaped wildcards
     $re1 = '(^|[^\\])(\\\\)+';
     // escaped wildcards
     while ($row = PMA_mysql_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_str = substr($row[0], 6, strpos($row[0], ' ON ') - 6);
         if ($show_grants_str == 'ALL' || $show_grants_str == 'ALL PRIVILEGES' || $show_grants_str == 'CREATE' || strpos($show_grants_str, 'CREATE')) {
             if ($show_grants_dbname == '*') {
                 $is_create_priv = TRUE;
                 $db_to_create = '';
                 break;
             } else {
                 if (ereg($re0 . '%|_', $show_grants_dbname) || !PMA_mysql_select_db($show_grants_dbname, $userlink) && @mysql_errno() != 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);
                     // and remove backquotes
                     $db_to_create = str_replace('`', '', $db_to_create);
                     $is_create_priv = TRUE;
                     break;
Пример #13
0
/**
 * Gets all Relations to foreign tables for a given table or
 * optionally a given column in a table
 *
 * @param   string   the name of the db to check for
 * @param   string   the name of the table to check for
 * @param   string   the name of the column to check for
 * @param   string   the source for foreign key information
 *
 * @return  array    db,table,column
 *
 * @global  array    the list of relations settings
 * @global  string   the URL of the page to show in case of error
 *
 * @access  public
 *
 * @author  Mike Beck <*****@*****.**> and Marc Delisle
 */
function PMA_getForeigners($db, $table, $column = '', $source = 'both')
{
    global $cfgRelation, $err_url_0;
    if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) {
        $rel_query = 'SELECT master_field, foreign_db, foreign_table, foreign_field' . ' FROM ' . PMA_backquote($cfgRelation['relation']) . ' WHERE master_db =  \'' . PMA_sqlAddslashes($db) . '\' ' . ' AND   master_table = \'' . PMA_sqlAddslashes($table) . '\' ';
        if (!empty($column)) {
            $rel_query .= ' AND master_field = \'' . PMA_sqlAddslashes($column) . '\'';
        }
        $relations = PMA_query_as_cu($rel_query);
        $i = 0;
        while ($relrow = @PMA_mysql_fetch_array($relations)) {
            $field = $relrow['master_field'];
            $foreign[$field]['foreign_db'] = $relrow['foreign_db'];
            $foreign[$field]['foreign_table'] = $relrow['foreign_table'];
            $foreign[$field]['foreign_field'] = $relrow['foreign_field'];
            $i++;
        }
        // end while
    }
    if (($source == 'both' || $source == 'innodb') && !empty($table)) {
        $show_create_table_query = 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table);
        $show_create_table_res = PMA_mysql_query($show_create_table_query);
        list(, $show_create_table) = PMA_mysql_fetch_row($show_create_table_res);
        $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
        foreach ($analyzed_sql[0]['foreign_keys'] as $one_key) {
            // the analyzer may return more than one column name in the
            // index list or the ref_index_list
            foreach ($one_key['index_list'] as $i => $field) {
                // If a foreign key is defined in the 'internal' source (pmadb)
                // and in 'innodb', we won't get it twice if $source='both'
                // because we use $field as key
                $foreign[$field]['constraint'] = $one_key['constraint'];
                if (isset($one_key['ref_db_name'])) {
                    $foreign[$field]['foreign_db'] = $one_key['ref_db_name'];
                } else {
                    $foreign[$field]['foreign_db'] = $db;
                }
                $foreign[$field]['foreign_table'] = $one_key['ref_table_name'];
                $foreign[$field]['foreign_field'] = $one_key['ref_index_list'][$i];
                if (isset($one_key['on_delete'])) {
                    $foreign[$field]['on_delete'] = $one_key['on_delete'];
                }
                if (isset($one_key['on_update'])) {
                    $foreign[$field]['on_update'] = $one_key['on_update'];
                }
            }
        }
    }
    if (isset($foreign) && is_array($foreign)) {
        return $foreign;
    } else {
        return FALSE;
    }
}