Ejemplo n.º 1
2
function db_test()
{
    include_once EZSQL_LIB . "/shared/ez_sql_core.php";
    include_once EZSQL_LIB . "/mysql/ez_sql_mysql.php";
    $db = new ezSQL_mysql(DB_USER, DB_PASSWD, DB_NAME, DB_HOST);
    return @$db->quick_connect(DB_USER, DB_PASSWD, DB_NAME, DB_HOST);
}
Ejemplo n.º 2
0
function phpbb_connect()
{
    global $settings, $db, $phpbb_db;
    if ($settings['user']) {
        $dbname = strpos($settings['db'], '.') > 0 ? substr($settings['db'], 0, strpos($settings['db'], '.')) : $settings['db'];
        $db1 = new ezSQL_mysql($settings['user'], $settings['pass'], $dbname, $settings['host']);
        $db1->show_errors = true;
        $db1->quick_connect($settings['user'], $settings['pass'], $dbname, $settings['host']);
        if (count($db1->captured_errors) > 0) {
            return null;
        }
        return $db1;
    } else {
        return $db;
    }
}
Ejemplo n.º 3
0
function database_setup($h, $settings_file_exists)
{
    global $lang;
    //already included so Hotaru can't re-include it
    if ($h->cage->post->KeyExists('updated')) {
        $settings = new \stdClass();
        $error = 0;
        // Test CSRF
        //	    if (!$h->csrf('check', 'index')) {
        //		    $h->messages[$lang['install_step3_csrf_error']] = 'red';
        //		    $error = 1;
        //	    }
        // Test baseurl
        $settings->baseurl_name = $h->cage->post->testUri('baseurl');
        if (!$settings->baseurl_name) {
            $h->messages[$lang['install_step1_baseurl_error']] = 'red';
            $error = 1;
        }
        // Test dbname
        $settings->dbuser_name = $h->cage->post->testAlnumLines('dbuser');
        if (!$settings->dbuser_name) {
            $h->messages[$lang['install_step1_dbuser_error']] = 'red';
            $error = 1;
        }
        // Test dbpassword
        $settings->dbpassword_name = $h->cage->post->KeyExists('dbpassword');
        if (!$settings->dbpassword_name) {
            $h->messages[$lang['install_step1_dbpassword_error']] = 'red';
            $error = 1;
        }
        // Test dbname
        $settings->dbname_name = $h->cage->post->testAlnumLines('dbname');
        if (!$settings->dbname_name) {
            $h->messages[$lang['install_step1_dbname_error']] = 'red';
            $error = 1;
        }
        // Test dbprefix
        $settings->dbprefix_name = $h->cage->post->testAlnumLines('dbprefix');
        if (!$settings->dbprefix_name) {
            $h->messages[$lang['install_step1_dbprefix_error']] = 'red';
            $error = 1;
        }
        // Test dbhost
        $settings->dbhost_name = $h->cage->post->testAlpha('dbhost');
        if (!$settings->dbhost_name) {
            $h->messages[$lang['install_step1_dbhost_error']] = 'red';
            $error = 1;
        }
    } else {
        $settings = settingsFile($settings_file_exists);
    }
    // Show messages
    if ($h->cage->post->getAlpha('updated') == 'true') {
        if (!$error) {
            // Try to write file to disk based on form inputs
            $fputs = create_new_settings_file($settings->dbuser_name, $settings->dbpassword_name, $settings->dbname_name, $settings->dbprefix_name, $settings->dbhost_name, $settings->baseurl_name);
            // if file written successfully then
            if ($fputs) {
                $h->messages[$lang['install_step1_update_file_writing_success']] = 'green';
                // if yes set warning message var
            } else {
                $h->messages[$lang['install_step1_update_file_writing_failure']] = 'red';
            }
        }
        @chmod(SETTINGS, 0644);
    }
    // Check whether database and tables exist on this server
    $db = new ezSQL_mysql($settings->dbuser_name, $settings->dbpassword_name, $settings->dbname_name, $settings->dbhost_name);
    $db->show_errors = false;
    $database_exists = $db->quick_connect($settings->dbuser_name, $settings->dbpassword_name, $settings->dbname_name, $settings->dbhost_name);
    $table_exists = $database_exists ? table_exists($db, 'miscdata', $settings->dbprefix_name) : false;
    $show_next = $database_exists ? true : false;
    if ($settings->dbpassword_name && !$database_exists) {
        $h->messages[$lang['install_step1_no_db_exists_failure']] = 'red';
    }
    // Try to write the /config/settings.php file to disk
    //
    @chmod(SETTINGS, 0777);
    $settings_file_writeable = is_writeable(SETTINGS);
    if ($settings_file_writeable) {
        // show template
        template($h, 'install/database_setup.php', array('settings_file_exists' => $settings_file_exists, 'cage' => $h->cage, 'table_exists' => $table_exists, 'show_next' => $show_next, 'baseurl_name' => $settings->baseurl_name, 'dbuser_name' => $settings->dbuser_name, 'dbpassword_name' => $settings->dbpassword_name, 'dbname_name' => $settings->dbname_name, 'dbprefix_name' => $settings->dbprefix_name, 'dbhost_name' => $settings->dbhost_name));
    } else {
        @chmod(SETTINGS, 0644);
        database_setup_manual($h);
    }
}
Ejemplo n.º 4
0
<?php

require_once "ez_sql_core.php";
require_once "ez_sql_mysql.php";
if (isset($configuration['database'])) {
    $db = new ezSQL_mysql();
    // auto connect to the db in order to have a valid connection when calling $db->escape() for creating queries
    $db->quick_connect($configuration['database']['username'], $configuration['database']['password'], $configuration['database']['name'], $configuration['database']['server']);
}