Exemple #1
0
function loadDatabase()
{
    global $db_persist, $db_connection, $db_server, $db_user, $db_passwd;
    global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix;
    // Figure out what type of database we are using.
    $db_type = 'mysql';
    // Load the file for the database.
    require_once $sourcedir . '/lib/Subs-Db-' . $db_type . '.php';
    // If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
    if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) {
        $db_connection = smf_db_initiate($db_server, $db_name, $ssi_db_user, $ssi_db_passwd, array('persist' => $db_persist, 'non_fatal' => true, 'dont_select_db' => true));
    }
    // Either we aren't in SSI mode, or it failed.
    if (empty($db_connection)) {
        $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, array('persist' => $db_persist, 'dont_select_db' => SMF == 'SSI'));
    }
    // Safe guard here, if there isn't a valid connection lets put a stop to it.
    if (!$db_connection) {
        db_fatal_error();
    }
    // If in SSI mode fix up the prefix.
    if (SMF == 'SSI') {
        db_fix_prefix($db_prefix, $db_name);
    }
}
Exemple #2
0
/**
 * Load the db connection
 *
 * Will add the db functions to $smcFunc array and set up and test the db connection
 *
 * @return bool if the db connection exists or not
 * @since  0.1.0
 */
function smfapi_loadDatabase()
{
    global $db_persist, $db_connection, $db_server, $db_user, $db_passwd;
    global $db_type, $db_name, $sourcedir, $db_prefix;
    // figure out what type of database we are using.
    if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
        $db_type = 'mysql';
    }
    // load the file for the database (safe to load)
    require_once $sourcedir . '/Subs-Db-' . $db_type . '.php';
    // make connection
    if (empty($db_connection)) {
        $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('persist' => $db_persist, 'dont_select_db' => SMF == 'API'));
    }
    // safe guard here, if there isn't a valid connection lets put a stop to it.
    if (!$db_connection) {
        return false;
    }
    // defined in Subs-Db-*.php
    db_fix_prefix($db_prefix, $db_name);
    return true;
}