CodeIgniter Forums

Full Version: Codeigniter database connection error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Unable to connect to database in Codeigniter:

I have changed mysql to mysqli in database.php but unable to connect to database.

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'administrator',
'database' => 'industry',
'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
);

A PHP Error was encountered

Severity: Warning

Message: mysqli::real_connect(): (HY000/2002): No connection could be made because the target machine actively refused it.

Filename: mysqli/mysqli_driver.php

Line Number: 201
We need to know what versions of php, CodeIgniter and your platform that you are running on?
(01-17-2017, 11:09 AM)InsiteFX Wrote: [ -> ]We need to know what versions of php, CodeIgniter and your platform that you are running on?

php version: 5.6.26

CodeIgniter: 3.1.2

WAMP Stack
@bhanuteja4
Also, are you sure of the password for root? (If you are using a database tool you can check the password by creating an account to access the database.)

Also try 127.0.0.1 in the place of localhost (since you are on Windows).
Hi @bhanuteja4,
Have you solved the error?
I have the same problem Huh

PHP: 5.4.16 (cli)
codeigniter: 3.1.3
mysql  Ver 14.14 Distrib 5.6.31, for Linux (x86_64) using  EditLine wrapper
These errors have nothing to do with codeigniter, but your database. Generally this error comes up when you are trying to connect to it over an ip or port which is not allowed. Most of the time, it has to do with the bind address set on your mysql database. This should give you a reference and more information.

http://stackoverflow.com/questions/22736...refused-it
I had the same error, easily it was the port number of the database in the apache. so you can just check the used port number and add it in database.php file.