简体   繁体   English

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

[英]Codeigniter Error Message on Live server : mysqli::real_connect(): (HY000/2002): Connection refused

I am creating a website using Codeigniter(version:3.05),php(version: 5.6.24), mysql(version: 10.1.16 mariaDB).我正在使用 Codeigniter(版本:3.05)、php(版本:5.6.24)、mysql(版本:10.1.16 mariaDB)创建一个网站。 At local server: operating system=OSX, php version=5.6.24, mysql version=10.1.16 mariaDB.在本地服务器:操作系统=OSX,php版本=5.6.24,mysql版本=10.1.16 mariaDB。 At Hosting server: operating system=FreeBSD(unix), phpversion= 5.6.30, mysql version=:5.5.38-log.在托管服务器上:操作系统=FreeBSD(unix),phpversion=5.6.30,mysql version=:5.5.38-log。 The site works fine on local server.该网站在本地服务器上运行良好。 But it gives error on live server as shown below.但它在实时服务器上给出错误,如下所示。

    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

I have been checking my database file(database.php) several time, but I didn't find any error there regarding hostname,username,password, database name.我一直在检查我的数据库文件 (database.php) 好几次,但我没有发现任何关于主机名、用户名、密码、数据库名称的错误。

database.php file数据库.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 file is as shown below: 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'] = '';

In your database.php instead of putting " localhost " try putting " 127.0.0.1 ".在您的 database.php 中,不要放置“ localhost ”,而是尝试放置“ 127.0.0.1 ”。 This works for most of the cases.这适用于大多数情况。

If you still get error then post you database.php file.如果仍然出现错误,请将 database.php 文件发布给您。

Use 'hostname' => 'localhost' instead of 'hostname' => 'testurl.com' .使用'hostname' => 'localhost'而不是'hostname' => 'testurl.com' Even though you upload your code on live server, hostname remains "localhost" only.即使您将代码上传到实时服务器上,主机名仍然只是“本地主机”。

Try like this.For local server.像这样尝试。对于本地服务器。

$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
);

Plese check Your localhost/localserver is start or not, if your server is not started ths problem may be create.请检查您的本地主机/本地服务器是否启动,如果您的服务器未启动,则可能会产生问题。 second possiblility is if your please check your credentials in config/database.php if is incorrect then please correct it..第二种可能性是,如果您在 config/database.php 中检查您的凭据,如果不正确,请更正它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CodeIgniter 消息:mysqli::real_connect():(HY000/2002):连接超时,在服务器中出现错误 - CodeIgniter Message: mysqli::real_connect(): (HY000/2002): Connection timed out giving error in server mysqli::real_connect(): (HY000/2002): 实时连接被拒绝 - mysqli::real_connect(): (HY000/2002): Connection refused on Live 数据库错误 mysqli::real_connect(): (HY000/2002): Connection denied codeingiter - Datebase error mysqli::real_connect(): (HY000/2002): Connection refused codeingiter phpMyAdmin mysqli::real_connect(): (HY000/2002): 连接被拒绝 - phpMyAdmin mysqli::real_connect(): (HY000/2002): Connection refused 获取“mysqli::real_connect(): (HY000/2002): 连接被拒绝” - Getting "mysqli::real_connect(): (HY000/2002): Connection refused" Docker MySQL mysqli::real_connect():(HY000/2002): 连接被拒绝 - Docker MySQL mysqli::real_connect():(HY000/2002): Connection refused mysqli::real_connect(): (HY000/2002): 由于目标机器主动拒绝,无法建立连接 - mysqli::real_connect(): (HY000/2002): No connection could be made because the target machine actively refused it 出现错误 mysqli::real_connect(): (HY000/2002): 当我尝试在实时服务器上访问我的项目时没有这样的文件或目录 - Getting error mysqli::real_connect(): (HY000/2002): No such file or directory when I try to access my project on live server WAMP和mysqli :: real_connect():(HY000 / 2002)? - WAMP and mysqli::real_connect(): (HY000/2002)? mysqli :: real_connect():(HY000 / 2002):在Cplesk中 - mysqli::real_connect(): (HY000/2002):in cplesk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM