Aman
Aman

Reputation: 5

CodeIgniter local database connection issue

I have tried this to make local database connection. But it gives this error:

You have specified an invalid database connection group (ci_test) in your config/database.php file.

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',  // pass this
    'username' => 'root',  // pass this
    'password' => '',  // pass this
    'database' => 'ci_test',  // pass this
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => TRUE,
    'db_debug' => TRUE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array());

Upvotes: 0

Views: 2102

Answers (3)

Jok3r
Jok3r

Reputation: 496

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


$db['default'] = array(

'dsn'   => '',
'hostname' => 'localhost', //this will be same
'username' => 'root',  //replace with your username
'password' => '',       //replace with your password
'database' => 'test',   //replace with your database name which you want to use
'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);

try this. good luck.

Upvotes: 1

NikuNj Rathod
NikuNj Rathod

Reputation: 1658

You can try this solution for your problem.

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

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

I hope this will helps you. Thanks!

Upvotes: 0

Jim Wright
Jim Wright

Reputation: 6058

This error relates to the connection group, not the database name. The connection group you have specified there is default, as shown on the first line: $db['default'].

Look for:

$active_group = 'ci_test';

Replace it with:

$active_group = 'default';

There is more information in the codeigniter documentation.

Upvotes: 0

Related Questions