首页 文章

Live服务器上的Codeigniter错误消息:mysqli :: real_connect():( HY000 / 2002):连接被拒绝

提问于
浏览
1

我正在使用Codeigniter(版本:3.05),php(版本:5.6.24),mysql(版本:10.1.16 mariaDB)创建一个网站 . 在本地服务器:操作系统= OSX,php版本= 5.6.24,mysql版本= 10.1.16 mariaDB . 在主机服务器:操作系统= FreeBSD(unix),phpversion = 5.6.30,mysql版本=:5.5.38-log . 该站点在本地服务器上正常工作 . 但它在实时服务器上出错,如下所示 .

A PHP Error was encountered

    Severity: Warning

    Message: mysqli::real_connect(): (HY000/2002): Connection refused

    Filename: mysqli/mysqli_driver.php

    Line Number: 202

    Backtrace:

    File: /home/sv-001/www/user/myweb/application/third_party/MX/Loader.php
    Line: 109
    Function: DB

    File: /home/sv-001/www/user/myweb/application/third_party/MX/Loader.php
    Line: 65
    Function: initialize

    File: /home/sv-001/www/user/myweb/application/modules/home/controllers/Home.php
    Line: 8
    Function: __construct

    File: /home/sv-001/www/user/myweb/index.php
    Line: 294
    Function: require_once

我已经多次检查我的数据库文件(database.php),但我没有发现有关主机名,用户名,密码,数据库名称的任何错误 .

database.php文件

$db['default'] = array(
        'dsn'   => '',
        'hostname' => 'testurl.com',
        'username' => 'username',
        'password' => 'password',
        'database' => 'dbname',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt' => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
);

config.php文件如下所示:

if($_SERVER['HTTP_HOST'] == "localhost" OR $_SERVER['HTTP_HOST'] == "testurl.com")
    $config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/myfolder/myfolder2/';
else if($_SERVER['HTTP_HOST'] == "testurl.com" OR $_SERVER['HTTP_HOST'] == "testurl.com")
    $config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/myfolder2/';
else
    $config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'];

$config['index_page'] = 'index.php';
//$config['index_page'] = '';

$config['uri_protocol'] = 'REQUEST_URI';

$config['url_suffix'] = '';

$config['language'] = 'english';

$config['charset'] = 'UTF-8';

$config['enable_hooks'] = FALSE;

$config['subclass_prefix'] = 'MY_';
$config['composer_autoload'] = FALSE;


$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';

$config['log_threshold'] = 0;

$config['log_path'] = '';

$config['log_file_extension'] = '';

$config['log_file_permissions'] = 0644;
$config['log_date_format'] = 'Y-m-d H:i:s';

$config['error_views_path'] = '';

$config['cache_path'] = '';

$config['cache_query_string'] = FALSE;

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
//$config['sess_save_path'] = NULL;
$config['sess_save_path'] = APPPATH . 'cache';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

$config['cookie_prefix']    = '';
$config['cookie_domain']    = '';
$config['cookie_path']      = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;

$config['standardize_newlines'] = FALSE;

$config['global_xss_filtering'] = FALSE;

$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
//$config['csrf_regenerate'] = TRUE;
$config['csrf_regenerate'] = FALSE;
$config['csrf_exclude_uris'] = array();
$config['compress_output'] = FALSE;

$config['time_reference'] = 'local';

$config['rewrite_short_tags'] = FALSE;

$config['proxy_ips'] = '';

3 回答

  • 1

    在您的database.php中,而不是放“ localhost " try putting " 127.0.0.1 ” . 这适用于大多数情况 .

    如果仍然出现错误,请发布database.php文件 .

  • 0

    使用 'hostname' => 'localhost' 而不是 'hostname' => 'testurl.com' . 即使您在实时服务器上上传代码,主机名仍然只是"localhost" .

  • 0

    试试这样 . 对于本地服务器 .

    $active_group = 'default';
    $query_builder = TRUE;
    
    $db['default'] = array(
        'dsn'      => '',
        'hostname' => 'localhost',
        'username' => '<user>',
        'password' => '<password>',
        'database' => '<database>',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt'  => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
    );
    

相关问题