当前位置: 首页>>代码示例>>PHP>>正文


PHP drupal_detect_database_types函数代码示例

本文整理汇总了PHP中drupal_detect_database_types函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_detect_database_types函数的具体用法?PHP drupal_detect_database_types怎么用?PHP drupal_detect_database_types使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了drupal_detect_database_types函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _install_settings_form_validate

/**
 * Helper function for install_settings_validate.
 */
function _install_settings_form_validate($database, $settings_file, &$form_state, $form = NULL)
{
    global $databases;
    // Verify the table prefix
    if (!empty($database['prefix']) && is_string($database['prefix']) && !preg_match('/^[A-Za-z0-9_.]+$/', $database['dprefix'])) {
        form_set_error('db_prefix', st('The database table prefix you have entered, %db_prefix, is invalid. The table prefix can only contain alphanumeric characters, periods, or underscores.', array('%db_prefix' => $db_prefix)), 'error');
    }
    if (!empty($database['port']) && !is_numeric($database['port'])) {
        form_set_error('db_port', st('Database port must be a number.'));
    }
    // Check database type
    $database_types = drupal_detect_database_types();
    $driver = $database['driver'];
    if (!isset($database_types[$driver])) {
        form_set_error('driver', st("In your %settings_file file you have configured @drupal to use a %driver server, however your PHP installation currently does not support this database type.", array('%settings_file' => $settings_file, '@drupal' => drupal_install_profile_name(), '%driver' => $database['driver'])));
    } else {
        if (isset($form)) {
            form_set_value($form['_database'], $database, $form_state);
        }
        $class = "DatabaseInstaller_{$driver}";
        $test = new $class();
        $databases = array('default' => array('default' => $database));
        $return = $test->test();
        if (!$return || $test->error) {
            if (!empty($test->success)) {
                form_set_error('db_type', st('In order for Drupal to work, and to continue with the installation process, you must resolve all permission issues reported above. We were able to verify that we have permission for the following commands: %commands. For more help with configuring your database server, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what any of this means you should probably contact your hosting provider.', array('%commands' => implode($test->success, ', '))));
            } else {
                form_set_error('driver', '');
            }
        }
    }
}
开发者ID:schuyler1d,项目名称:drupal,代码行数:35,代码来源:install.php

示例2: _install_settings_form_validate

/**
 * Helper function for install_settings_validate.
 */
function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_port, $db_path, $settings_file, &$form_state, $form = NULL)
{
    global $db_url;
    // Verify the table prefix
    if (!empty($db_prefix) && is_string($db_prefix) && !preg_match('/^[A-Za-z0-9_.]+$/', $db_prefix)) {
        form_set_error('db_prefix', st('The database table prefix you have entered, %db_prefix, is invalid. The table prefix can only contain alphanumeric characters, periods, or underscores.', array('%db_prefix' => $db_prefix)), 'error');
    }
    if (!empty($db_port) && !is_numeric($db_port)) {
        form_set_error('db_port', st('Database port must be a number.'));
    }
    // Check database type
    if (!isset($form)) {
        $_db_url = is_array($db_url) ? $db_url['default'] : $db_url;
        $db_type = substr($_db_url, 0, strpos($_db_url, '://'));
    }
    $databases = drupal_detect_database_types();
    if (!in_array($db_type, $databases)) {
        form_set_error('db_type', st("In your %settings_file file you have configured @drupal to use a %db_type server, however your PHP installation currently does not support this database type.", array('%settings_file' => $settings_file, '@drupal' => drupal_install_profile_name(), '%db_type' => $db_type)));
    } else {
        // Verify
        $db_url = $db_type . '://' . urlencode($db_user) . ($db_pass ? ':' . urlencode($db_pass) : '') . '@' . ($db_host ? urlencode($db_host) : 'localhost') . ($db_port ? ":{$db_port}" : '') . '/' . urlencode($db_path);
        if (isset($form)) {
            form_set_value($form['_db_url'], $db_url, $form_state);
        }
        $success = array();
        $function = 'drupal_test_' . $db_type;
        if (!$function($db_url, $success)) {
            if (isset($success['CONNECT'])) {
                form_set_error('db_type', st('In order for Drupal to work, and to continue with the installation process, you must resolve all permission issues reported above. We were able to verify that we have permission for the following commands: %commands. For more help with configuring your database server, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what any of this means you should probably contact your hosting provider.', array('%commands' => implode($success, ', '))));
            } else {
                form_set_error('db_type', '');
            }
        }
    }
}
开发者ID:alexismb5,项目名称:ckan-drupal,代码行数:38,代码来源:install.php

示例3: install_database_errors

/**
 * Check a database connection and return any errors.
 */
function install_database_errors($database, $settings_file)
{
    global $databases;
    $errors = array();
    // Verify the table prefix
    if (!empty($database['db_prefix']) && is_string($database['db_prefix']) && !preg_match('/^[A-Za-z0-9_.]+$/', $database['db_prefix'])) {
        $errors['db_prefix'] = st('The database table prefix you have entered, %db_prefix, is invalid. The table prefix can only contain alphanumeric characters, periods, or underscores.', array('%db_prefix' => $database['db_prefix']));
    }
    if (!empty($database['port']) && !is_numeric($database['port'])) {
        $errors['db_port'] = st('Database port must be a number.');
    }
    // Check database type
    $database_types = drupal_detect_database_types();
    $driver = $database['driver'];
    if (!isset($database_types[$driver])) {
        $errors['driver'] = st("In your %settings_file file you have configured @drupal to use a %driver server, however your PHP installation currently does not support this database type.", array('%settings_file' => $settings_file, '@drupal' => drupal_install_profile_name(), '%driver' => $database['driver']));
    } else {
        // Run tasks associated with the database type. Any errors are caught in the
        // calling function
        $databases['default']['default'] = $database;
        // Just changing the global doesn't get the new information processed.
        // We tell tell the Database class to re-parse $databases.
        Database::parseConnectionInfo();
        try {
            db_run_tasks($database['driver']);
        } catch (DatabaseTaskException $e) {
            // These are generic errors, so we do not have any specific key of the
            // database connection array to attach them to; therefore, we just put
            // them in the error array with standard numeric keys.
            $errors[] = $e->getMessage();
        }
    }
    return $errors;
}
开发者ID:blipp,项目名称:drupal,代码行数:37,代码来源:install.php


注:本文中的drupal_detect_database_types函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。