예제 #1
0
function connect_error()
{
    global $adminer, $connection, $token, $error, $drivers;
    if (DB != "") {
        header("HTTP/1.1 404 Not Found");
        page_header(lang('Database') . ": " . h(DB), lang('Invalid database.'), true);
    } else {
        if ($_POST["db"] && !$error) {
            queries_redirect(substr(ME, 0, -1), lang('Databases have been dropped.'), drop_databases($_POST["db"]));
        }
        //Encabezado y botones de la parte superior en la seleccion de bases de datos
        page_header(lang('Select database'), $error, false);
        echo "<p>\n";
        foreach (array('database' => lang('Create new database'), 'privileges' => lang('Privileges'), 'processlist' => lang('Process list'), 'variables' => lang('Variables'), 'status' => lang('Status')) as $key => $val) {
            if (support($key)) {
                echo "<a class='btn btn-xs btn-primary' href='" . h(ME) . "{$key}='>{$val}</a>\n";
            }
        }
        //Presenta informacion de la conexion
        echo "<p><i class='fa fa-exchange fa-fw'></i> " . lang('%s version: %s through PHP extension %s', $drivers[DRIVER], "<b>" . h($connection->server_info) . "</b>", "<b>{$connection->extension}</b>") . "\n";
        echo "<p><i class='fa fa-user fa-fw'></i> " . lang('Logged as: %s', "<b>" . h(logged_user()) . "</b>") . "\n";
        //Presenta la lista de bases de datos existentes y los encabezados
        $databases = $adminer->databases();
        if ($databases) {
            $scheme = support("scheme");
            $collations = collations();
            echo "<form action='' method='post'>\n";
            echo "<table cellspacing='0' class='checkable table table-condensed table-responsive table-hover' onclick='tableClick(event);' ondblclick='tableClick(event, true);'>\n";
            echo "<thead><tr>" . (support("database") ? "<th>&nbsp;" : "") . "<th>" . lang('Database') . " - <a class='btn btn-default btn-xs' href='" . h(ME) . "refresh=1'><i class='fa fa-refresh fa-fw'></i> " . lang('Refresh') . "</a>" . "<th>" . lang('Collation') . "<th>" . lang('Tables') . "<th>" . lang('Size') . " - <a  class='btn btn-default btn-xs' href='" . h(ME) . "dbsize=1' onclick=\"return !ajaxSetHtml('" . js_escape(ME) . "script=connect');\">" . lang('Compute') . "</a>" . "</thead>\n";
            //Presenta la lista de bases de datos
            $databases = $_GET["dbsize"] ? count_tables($databases) : array_flip($databases);
            foreach ($databases as $db => $tables) {
                $root = h(ME) . "db=" . urlencode($db);
                echo "<tr" . odd() . ">" . (support("database") ? "\n\t\t\t\t\t<td align=center>" . checkbox("db[]", $db, in_array($db, (array) $_POST["db"])) : "");
                echo "<th><a  href='{$root}'>" . h($db) . "</a>";
                $collation = nbsp(db_collation($db, $collations));
                echo "<td>" . (support("database") ? "<a href='{$root}" . ($scheme ? "&amp;ns=" : "") . "&amp;database=' title='" . lang('Alter database') . "'>{$collation}</a>" : $collation);
                echo "<td align='right'><a href='{$root}&amp;schema=' id='tables-" . h($db) . "' title='" . lang('Database schema') . "'>" . ($_GET["dbsize"] ? $tables : "?") . "</a>";
                echo "<td align='right' id='size-" . h($db) . "'>" . ($_GET["dbsize"] ? db_size($db) : "?");
                echo "\n";
            }
            echo "</table>\n";
            //Agrega boton de eliminar
            echo support("database") ? "<fieldset><legend>" . lang('Selected') . " <span id='selected'></span></legend><div>\n" . "<input type='hidden' name='all' value='' onclick=\"selectCount('selected', formChecked(this, /^db/));\">\n" . "<input class='btn btn-xs btn-danger' type='submit' name='drop' value='" . lang('Drop') . "'" . confirm() . ">\n" . "</div></fieldset>\n" : "";
            echo "<script type='text/javascript'>tableCheck();</script>\n";
            echo "<input type='hidden' name='token' value='{$token}'>\n";
            echo "</form>\n";
        }
    }
    page_footer("db");
}
예제 #2
0
function connect_error()
{
    global $connection, $token, $error, $drivers;
    $databases = array();
    if (DB != "") {
        page_header(lang('Database') . ": " . h(DB), lang('Invalid database.'), true);
    } else {
        if ($_POST["db"] && !$error) {
            queries_redirect(substr(ME, 0, -1), lang('Databases have been dropped.'), drop_databases($_POST["db"]));
        }
        page_header(lang('Select database'), $error, false);
        echo "<p><a href='" . h(ME) . "database='>" . lang('Create new database') . "</a>\n";
        foreach (array('privileges' => lang('Privileges'), 'processlist' => lang('Process list'), 'variables' => lang('Variables'), 'status' => lang('Status')) as $key => $val) {
            if (support($key)) {
                echo "<a href='" . h(ME) . "{$key}='>{$val}</a>\n";
            }
        }
        echo "<p>" . lang('%s version: %s through PHP extension %s', $drivers[DRIVER], "<b>{$connection->server_info}</b>", "<b>{$connection->extension}</b>") . "\n";
        echo "<p>" . lang('Logged as: %s', "<b>" . h(logged_user()) . "</b>") . "\n";
        if ($_GET["refresh"]) {
            set_session("dbs", null);
        }
        $databases = get_databases();
        if ($databases) {
            $scheme = support("scheme");
            $collations = collations();
            echo "<form action='' method='post'>\n";
            echo "<table cellspacing='0' class='checkable' onclick='tableClick(event);'>\n";
            echo "<thead><tr><td>&nbsp;<th>" . lang('Database') . "<td>" . lang('Collation') . "<td>" . lang('Tables') . "</thead>\n";
            foreach ($databases as $db) {
                $root = h(ME) . "db=" . urlencode($db);
                echo "<tr" . odd() . "><td>" . checkbox("db[]", $db, in_array($db, (array) $_POST["db"]));
                echo "<th><a href='{$root}'>" . h($db) . "</a>";
                echo "<td><a href='{$root}" . ($scheme ? "&amp;ns=" : "") . "&amp;database=' title='" . lang('Alter database') . "'>" . nbsp(db_collation($db, $collations)) . "</a>";
                echo "<td align='right'><a href='{$root}&amp;schema=' id='tables-" . h($db) . "' title='" . lang('Database schema') . "'>?</a>";
                echo "\n";
            }
            echo "</table>\n";
            echo "<script type='text/javascript'>tableCheck();</script>\n";
            echo "<p><input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm("formChecked(this, /db/)", 1) . ">\n";
            // 1 - eventStop
            echo "<input type='hidden' name='token' value='{$token}'>\n";
            echo "<a href='" . h(ME) . "refresh=1' onclick='eventStop(event);'>" . lang('Refresh') . "</a>\n";
            echo "</form>\n";
        }
    }
    page_footer("db");
    if ($databases) {
        echo "<script type='text/javascript'>ajaxSetHtml('" . js_adminer_escape(ME) . "script=connect');</script>\n";
    }
}
예제 #3
0
        }
    } else {
        // alter database
        if (!$row["collation"]) {
            adminer_redirect(substr(ME, 0, -1));
        }
        query_adminer_redirect("ALTER DATABASE " . idf_escape($name) . (preg_match('~^[a-z0-9_]+$~i', $row["collation"]) ? " COLLATE {$row['collation']}" : ""), substr(ME, 0, -1), lang('Database has been altered.'));
    }
}
page_header(DB != "" ? lang('Alter database') : lang('Create database'), $error, array(), h(DB));
$collations = collations();
$name = DB;
if ($_POST) {
    $name = $row["name"];
} elseif (DB != "") {
    $row["collation"] = db_collation(DB, $collations);
} elseif ($jush == "sql") {
    // propose database name with limited privileges
    foreach (get_vals("SHOW GRANTS") as $grant) {
        if (preg_match('~ ON (`(([^\\\\`]|``|\\\\.)*)%`\\.\\*)?~', $grant, $match) && $match[1]) {
            $name = stripcslashes(idf_unescape("`{$match['2']}`"));
            break;
        }
    }
}
?>

<form action="" method="post">
<p>
<?php 
echo ($_POST["add_x"] || strpos($name, "\n") ? '<textarea id="name" name="name" rows="10" cols="40">' . h($name) . '</textarea><br>' : '<input name="name" id="name" value="' . h($name) . '" maxlength="64" autocapitalize="off">') . "\n" . ($collations ? html_select("collation", array("" => "(" . lang('collation') . ")") + $collations, $row["collation"]) . doc_link(array('sql' => "charset-charsets.html", 'mssql' => "ms187963.aspx")) : "");
예제 #4
0
 $tbl_administrators = prefix('administrators');
 $tbl_admin_to_object = prefix('admin_to_object');
 $tbl_tags = prefix('tags');
 $tbl_obj_to_tag = prefix('obj_to_tag');
 $tbl_captcha = prefix('captcha');
 $tbl_news = prefix('news');
 $tbl_pages = prefix('pages');
 $tbl_news_categories = prefix('news_categories');
 $tbl_news2cat = prefix('news2cat');
 $tbl_menu_manager = prefix('menu');
 $tbl_plugin_storage = prefix('plugin_storage');
 $tbl_searches = prefix('search_cache');
 // Prefix the constraint names:
 $db_schema = array();
 $sql_statements = array();
 $collation = db_collation();
 /*						 * *********************************************************************************
 						  Add new fields in the upgrade section. This section should remain static except for new
 						  tables. This tactic keeps all changes in one place so that noting gets accidentaly omitted.
 						 * ********************************************************************************** */
 //v1.2
 if (isset($create[$_zp_conf_vars['mysql_prefix'] . 'captcha'])) {
     $db_schema[] = "CREATE TABLE IF NOT EXISTS {$tbl_captcha} (\n\t\t`id` int(11) UNSIGNED NOT NULL auto_increment,\n\t\t`ptime` int(32) UNSIGNED NOT NULL,\n\t\t`hash` varchar(255) NOT NULL,\n\t\tPRIMARY KEY (`id`)\n\t\t)\t{$collation};";
 }
 //v1.1.7
 if (isset($create[$_zp_conf_vars['mysql_prefix'] . 'options'])) {
     $db_schema[] = "CREATE TABLE IF NOT EXISTS {$tbl_options} (\n\t\t`id` int(11) UNSIGNED NOT NULL auto_increment,\n\t\t`ownerid` int(11) UNSIGNED NOT NULL DEFAULT 0,\n\t\t`name` varchar(191) NOT NULL,\n\t\t`value` text,\n\t\t`theme` varchar (127) NOT NULL,\n\t\t`creator` varchar (255) DEFAULT NULL,\n\t\tPRIMARY KEY (`id`),\n\t\tUNIQUE (`name`, `ownerid`, `theme`)\n\t\t)\t{$collation};";
 }
 if (isset($create[$_zp_conf_vars['mysql_prefix'] . 'tags'])) {
     $db_schema[] = "CREATE TABLE IF NOT EXISTS {$tbl_tags} (\n\t\t`id` int(11) UNSIGNED NOT NULL auto_increment,\n\t\t`name` varchar(255) NOT NULL,\n\t\tPRIMARY KEY (`id`),\n\t\tUNIQUE (`name`)\n\t\t)\t{$collation};";
 }
예제 #5
0
/**
 * create the database
 */
function db_create()
{
    global $_zp_DB_details;
    $sql = 'CREATE DATABASE IF NOT EXISTS ' . '`' . $_zp_DB_details['mysql_database'] . '`' . db_collation();
    return query($sql, false);
}
예제 #6
0
     echo '<th>' . (support("table") || support("indexes") ? '<a href="' . h(ME) . 'table=' . urlencode($name) . '" title="' . lang('Show structure') . '">' . h($name) . '</a>' : h($name));
     if ($view) {
         echo '<td colspan="6"><a href="' . h(ME) . "view=" . urlencode($name) . '" title="' . lang('Alter view') . '">' . (preg_match('~materialized~i', $type) ? lang('Materialized View') : lang('View')) . '</a>';
         echo '<td align="right"><a href="' . h(ME) . "select=" . urlencode($name) . '" title="' . lang('Select data') . '">?</a>';
     } else {
         foreach (array("Engine" => array(), "Collation" => array(), "Data_length" => array("create", lang('Alter table')), "Index_length" => array("indexes", lang('Alter indexes')), "Data_free" => array("edit", lang('New item')), "Auto_increment" => array("auto_increment=1&create", lang('Alter table')), "Rows" => array("select", lang('Select data'))) as $key => $link) {
             $id = " id='{$key}-" . h($name) . "'";
             echo $link ? "<td align='right'>" . (support("table") || $key == "Rows" || support("indexes") && $key != "Data_length" ? "<a href='" . h(ME . "{$link['0']}=") . urlencode($name) . "'{$id} title='{$link['1']}'>?</a>" : "<span{$id}>?</span>") : "<td id='{$key}-" . h($name) . "'>&nbsp;";
         }
         $tables++;
     }
     echo support("comment") ? "<td id='Comment-" . h($name) . "'>&nbsp;" : "";
 }
 echo "<tr><td>&nbsp;<th>" . lang('%d in total', count($tables_list));
 echo "<td>" . nbsp($jush == "sql" ? $connection->result("SELECT @@storage_engine") : "");
 echo "<td>" . nbsp(db_collation(DB, collations()));
 foreach (array("Data_length", "Index_length", "Data_free") as $key) {
     echo "<td align='right' id='sum-{$key}'>&nbsp;";
 }
 echo "</table>\n";
 if (!information_schema(DB)) {
     $vacuum = "<input type='submit' value='" . lang('Vacuum') . "'" . on_help("'VACUUM'") . "> ";
     $optimize = "<input type='submit' name='optimize' value='" . lang('Optimize') . "'" . on_help($jush == "sql" ? "'OPTIMIZE TABLE'" : "'VACUUM OPTIMIZE'") . "> ";
     echo "<fieldset><legend>" . lang('Selected') . " <span id='selected'></span></legend><div>" . ($jush == "sqlite" ? $vacuum : ($jush == "pgsql" ? $vacuum . $optimize : ($jush == "sql" ? "<input type='submit' value='" . lang('Analyze') . "'" . on_help("'ANALYZE TABLE'") . "> " . $optimize . "<input type='submit' name='check' value='" . lang('Check') . "'" . on_help("'CHECK TABLE'") . "> " . "<input type='submit' name='repair' value='" . lang('Repair') . "'" . on_help("'REPAIR TABLE'") . "> " : ""))) . "<input type='submit' name='truncate' value='" . lang('Truncate') . "'" . confirm() . on_help($jush == "sqlite" ? "'DELETE'" : "'TRUNCATE" . ($jush == "pgsql" ? "'" : " TABLE'")) . "> " . "<input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm() . on_help("'DROP TABLE'") . ">\n";
     $databases = support("scheme") ? $adminer->schemas() : $adminer->databases();
     if (count($databases) != 1 && $jush != "sqlite") {
         $db = isset($_POST["target"]) ? $_POST["target"] : (support("scheme") ? $_GET["ns"] : DB);
         echo "<p>" . lang('Move to other database') . ": ";
         echo $databases ? html_select("target", $databases, $db) : '<input name="target" value="' . h($db) . '" autocapitalize="off">';
         echo " <input type='submit' name='move' value='" . lang('Move') . "'>";
         echo support("copy") ? " <input type='submit' name='copy' value='" . lang('Copy') . "'>" : "";
예제 #7
0
        // alter database
        if (!$_POST["collation"]) {
            redirect(substr(ME, 0, -1));
        }
        query_redirect("ALTER DATABASE " . idf_escape($name) . (eregi('^[a-z0-9_]+$', $_POST["collation"]) ? " COLLATE {$_POST['collation']}" : ""), substr(ME, 0, -1), lang('Database has been altered.'));
    }
}
page_header(DB != "" ? lang('Alter database') : lang('Create database'), $error, array(), DB);
$collations = collations();
$name = DB;
$collate = null;
if ($_POST) {
    $name = $_POST["name"];
    $collate = $_POST["collation"];
} elseif (DB != "") {
    $collate = db_collation(DB, $collations);
} elseif ($jush == "sql") {
    // propose database name with limited privileges
    foreach (get_vals("SHOW GRANTS") as $grant) {
        if (preg_match('~ ON (`(([^\\\\`]|``|\\\\.)*)%`\\.\\*)?~', $grant, $match) && $match[1]) {
            $name = stripcslashes(idf_unescape("`{$match['2']}`"));
            break;
        }
    }
}
?>

<form action="" method="post">
<p>
<?php 
echo ($_POST["add_x"] || strpos($name, "\n") ? '<textarea id="name" name="name" rows="10" cols="40">' . h($name) . '</textarea><br>' : '<input id="name" name="name" value="' . h($name) . '" maxlength="64">') . "\n" . ($collations ? html_select("collation", array("" => "(" . lang('collation') . ")") + $collations, $collate) : "");
/**
 * Establish a new database connection to the MySQL server
 * @param string $namespace Namespace of the configuration.
 */
function db_connect($namespace = 'default')
{
    global $_conn;
    global $_DB;
    $conf = db_config($namespace);
    # Connection
    $_conn = mysqli_connect($conf['host'], $conf['username'], $conf['password']);
    if (!$_conn) {
        die('Not connected mysqli!');
    }
    # Force MySQL to use the UTF-8 character set. Also set the collation, if a certain one has been set;
    # otherwise, MySQL defaults to 'utf8_general_ci' # for UTF-8.
    if (!db_setCharset('utf8')) {
        printf("Error loading character set utf8: %s", mysqli_error($_conn));
    }
    if (db_collation()) {
        db_query('SET NAMES utf8 COLLATE ' . db_collation());
    }
    # Select DB
    if (!mysqli_select_db($_conn, $conf['database'])) {
        die('Can\'t use  : ' . $conf['database'] . ' - ' . mysqli_error($_conn));
    }
    $_DB = new stdClass();
    $_DB->name = $conf['database'];
    $_DB->namespace = $namespace;
    # Load the schema of the currently connected database
    $schema = _schema($namespace, true);
    $_DB->schemaManager = new SchemaManager($schema);
    if (!$_DB->schemaManager->isLoaded()) {
        $_DB->schemaManager->build($namespace);
    }
}