title: Codeigniter Error Message on Live server : mysqli::real_connect(): (HY000/2002): Connection refused
body: <p>I am creating a website using Codeigniter(version:3.05),php(version: 5.6.24), mysql(version: 10.1.16 mariaDB). At local server: operating system=OSX, php version=5.6.24, mysql version=10.1.16 mariaDB. At Hosting server: operating system=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.</p>
  
  <pre><code>    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
  </code></pre>
  
  <p>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.</p>
  
  <p>database.php file</p>
  
  <pre><code>$db['default'] = array(
          'dsn'   =&gt; '',
          'hostname' =&gt; 'testurl.com',
          'username' =&gt; 'username',
          'password' =&gt; 'password',
          'database' =&gt; 'dbname',
          'dbdriver' =&gt; 'mysqli',
          'dbprefix' =&gt; '',
          'pconnect' =&gt; FALSE,
          'db_debug' =&gt; (ENVIRONMENT !== 'production'),
          'cache_on' =&gt; FALSE,
          'cachedir' =&gt; '',
          'char_set' =&gt; 'utf8',
          'dbcollat' =&gt; 'utf8_general_ci',
          'swap_pre' =&gt; '',
          'encrypt' =&gt; FALSE,
          'compress' =&gt; FALSE,
          'stricton' =&gt; FALSE,
          'failover' =&gt; array(),
          'save_queries' =&gt; TRUE
  );
  </code></pre>
  
  <p>config.php file is as shown below:</p>
  
  <pre><code>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'] = '';
  </code></pre>